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

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

问题描述

我有一个 Xamarin.Forms 解决方案,其中在每个项目(Android、iOS 和 Windows 8.1)中都包含一个名为 Plugin.SecureStorage 的库,来自此处:https://github.com/sameerkapps/SecureStorage我在每个项目中都通过 NuGET 安装了它.

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

<代码>[...]加载的程序集:MonoDroidConstructors [外部]09-27 18:14:49.880 D/Mono (30329):组装参考地址 AppConsume.Droid[0xb8cb0608] ->mscorlib[0xb8c64bc0]:2309-27 18:14:49.890 D/Mono (30329):组装参考地址 Xamarin.Forms.Core[0xb8cbca58] ->System.Collections[0xb8cc5980]:309-27 18:14:49.900 D/Mono (30329):组装参考地址 Xamarin.Forms.Core[0xb8cbca58] ->System.Threading[0xb8cd4948]:309-27 18:14:49.930 D/Mono (30329):组装参考地址 AppConsume.Droid[0xb8cb0608] ->Plugin.SecureStorage[0xb8cb43f8]:2未处理的异常:System.TypeLoadException:无法使用令牌 01000019 解析类型

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

当然,作为要求,我添加了这一行...

SecureStorageImplementation.StoragePassword = "mypass";

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

使用系统;使用 Android.App;使用 Android.Content.PM;使用 Android.Runtime;使用 Android.Views;使用 Android.Widget;使用Android.OS;使用 Plugin.SecureStorage;命名空间 MyApp.Droid{[活动(标签 =MyApp",图标 =@dr​​awable/icon",MainLauncher = true,ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]公共类 MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity{protected override void OnCreate(Bundle bundle){base.OnCreate(捆绑);SecureStorageImplementation.StoragePassword = "mypass";global::Xamarin.Forms.Forms.Init(this, bundle);加载应用程序(新应用程序());}}}

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

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

解决方案

这里是完整的解决方案

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

    中创建SecureStorageLinkerOverride.cs<前>使用系统;使用 Plugin.SecureStorage;命名空间 MyApp.Droid{公共静态类 LinkerPreserve{静态 LinkerPreserve(){抛出新异常(typeof(SecureStorageImplementation).FullName);}}

     公共类 PreserveAttribute : 属性{}

    }

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

现在运行您的项目.对于任何其他标记为答案的问题,请在下方评论.

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.

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";

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.

解决方案

Here is the complete solution

  1. Install nuget package https://www.nuget.org/packages/sameerIOTApps.Plugin.SecureStorage/
  2. Create SecureStorageLinkerOverride.cs in Droid project

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

        public class PreserveAttribute : Attribute
       {
       }
    

    }

  3. 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天全站免登陆