System.TypeLoadException:无法解析令牌为01000019的类型 [英] System.TypeLoadException: Could not resolve type with token 01000019

查看:720
本文介绍了System.TypeLoadException:无法解析令牌为01000019的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Xamarin.Forms解决方案,它在每个项目(Android,iOS和Windows 8.1)中都包含一个名为Plugin.SecureStorage的库,从这里开始: https://github.com/sameerkapps/SecureStorage 我是通过NuGET在每个项目中安装的.

I have a Xamarin.Forms solution which contains in each project (Android, iOS and Windows 8.1) a lib called Plugin.SecureStorage from here: https://github.com/sameerkapps/SecureStorage I installed it via NuGET in each project.

一切都可以在iOS和Windows 8.1上正常运行,问题出在Android上. Android中的项目正确构建,但是在启动时我得到了这个信息:

Everything works fine in iOS and Windows 8.1, the problem is in Android. The project in Android builds correctly, however at startup I get this:

[...]
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

这是什么意思?对我来说有点神秘.我该如何解决这个问题?

What it does mean? is a bit cryptic to me. How can I resolve this problem?

当然,根据要求,我添加了这一行...

Of course, as a requirement, I added this line...

SecureStorageImplementation.StoragePassword = "mypass";

在Android项目的MainActivity.cs中...

in the MainActivity.cs of the Android project...

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());
        }
    }
}

我还发现,更改行的位置会引发异常,这会抛出不同的令牌类型".

I also found that changing the line position throws different 'token types' in the exception.

更新:我刚刚发现该应用在以发布模式编译时成功运行.但是,我想解决的问题不是在调试"模式下工作,我认为这不在此问题的范围之内.

UPDATE: I just found the app runs sucessfully when compiling in Release Mode. However, not working in Debug mode is a problem that I would like to fix I don't think that is out of scope of this question.

推荐答案

这是完整的解决方案

  1. 安装nuget软件包 https://www.nuget.org/packages/sameerIOTApps .Plugin.SecureStorage/
  2. Droid 项目


using System;
using Plugin.SecureStorage;

namespace MyApp.Droid
{
    public static class LinkerPreserve
    {
        static LinkerPreserve()
        {
            throw new Exception(typeof(SecureStorageImplementation).FullName);
        }
    }

    public class PreserveAttribute : Attribute
   {
   }

}

  • 右键单击Droid项目->属性-> Android选项->链接器->仅SDK程序集"

  • Right click on Droid Project -> Property -> Android Option-> Linker -> "SDK Assemblies Only"

    现在运行您的项目.如有其他任何问题,请在下方评论,以使其得到回答.

    Now run your project. Comment bellow for any issues else marked it answer.

    这篇关于System.TypeLoadException:无法解析令牌为01000019的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆