Mr_*_*Mac 13 c# android xamarin.forms
我有一个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
Run Code Online (Sandbox Code Playgroud)
它的意思是什么?对我来说有点神秘.我该如何解决这个问题?
当然,作为一项要求,我添加了这一行......
SecureStorageImplementation.StoragePassword = "mypass";
Run Code Online (Sandbox Code Playgroud)
在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());
}
}
}
Run Code Online (Sandbox Code Playgroud)
我还发现更改行位置会在异常中抛出不同的"令牌类型".
更新:我发现在发布模式下编译时,应用程序运行成功.但是,不在调试模式下工作是一个我想修复的问题我不认为这超出了这个问题的范围.
小智 39
同样的错误对我而言.
问题:
Xamarin.Forms我的解决方案中有不同版本的软件包.
解:
您的Core,Droid和IOS项目的Xamarin.Forms版本更改.确保所有版本都相同.
我希望这有效.
这是完整的解决方案
在Droid项目中创建SecureStorageLinkerOverride.cs
使用系统;
使用插件.SecureStorage;
命名空间 MyApp.Droid
{
公共静态类 LinkerPreserve
{
静态 LinkerPreserve()
{
抛出新的异常(typeof(SecureStorageImplementation).FullName);
}
}
public class PreserveAttribute : Attribute
{
}
Run Code Online (Sandbox Code Playgroud)
}
右键单击 Droid 项目 -> 属性 -> Android 选项 -> 链接器 -> “仅 SDK 程序集”
现在运行您的项目。对于其他标记为答案的任何问题,请在下面评论。