【发布时间】:2017-02-06 17:51:44
【问题描述】:
我有一个 Xamarin.Forms 解决方案,它在每个项目(Android、iOS 和 Windows 8.1)中都包含一个名为 Plugin.SecureStorage 的库,来自此处: https://github.com/sameerkapps/SecureStorage 我在每个项目中通过 NuGET 安装它。
在 iOS 和 Windows 8.1 中一切正常,问题出在 Android 上。 Android中的项目可以正确构建,但是在启动时我得到了这个:
[...]
Loaded assembly: MonoDroidConstructors [External]
09-27 18:14:49.880 D/Mono (30329): Assembly Ref addref AppConsume.Droid[0xb8cb0608] -> mscorlib[0xb8c64bc0]: 23
09-27 18:14:49.890 D/Mono (30329): Assembly Ref addref Xamarin.Forms.Core[0xb8cbca58] -> System.Collections[0xb8cc5980]: 3
09-27 18:14:49.900 D/Mono (30329): Assembly Ref addref Xamarin.Forms.Core[0xb8cbca58] -> System.Threading[0xb8cd4948]: 3
09-27 18:14:49.930 D/Mono (30329): Assembly Ref addref AppConsume.Droid[0xb8cb0608] -> Plugin.SecureStorage[0xb8cb43f8]: 2
Unhandled Exception:
System.TypeLoadException: Could not resolve type with token 01000019
这是什么意思?对我来说有点神秘。我该如何解决这个问题?
当然,作为要求,我添加了这一行...
SecureStorageImplementation.StoragePassword = "mypass";
在Android项目的MainActivity.cs中...
using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Plugin.SecureStorage;
namespace MyApp.Droid
{
[Activity(Label = "MyApp", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SecureStorageImplementation.StoragePassword = "mypass";
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
}
}
我还发现更改行位置会在异常中引发不同的“令牌类型”。
更新:我刚刚发现应用程序在发布模式下编译时运行成功。但是,不在调试模式下工作是我想解决的问题,我认为这超出了这个问题的范围。
【问题讨论】:
-
在执行非常糟糕的代码合并之后,除了令牌 0100002a 之外,我也收到了这个错误,但是当我注释掉命名空间范围和/或 App 类 XAMLC 注释时,错误就会消失。我最终重新开始合并,问题就消失了。
标签: c# android xamarin.forms