'Android.Runtime.UncaughtExceptionHandler' 的类型初始值设定项抛出异常

The type initializer for 'Android.Runtime.UncaughtExceptionHandler' threw an exception

我的 xamarin android 应用程序运行良好,但在每次启动时都开始崩溃并出现此异常。

该应用程序一如既往地从 appcenter 的构建服务构建。如果我在调试或发布模式下在本地构建它,它可以正常启动。使用 Android 7.

的设备

有没有人遇到过这个异常并且知道该怎么办?
泰!

18828 W monodroid: Calling into managed runtime init E mono : E mono : Unhandled Exception: E mono : System.TypeInitializationException: The type initializer for 'Android.Runtime.UncaughtExceptionHandler' threw an exception. ---> System.ArgumentNullException: Value cannot be null. E mono : Parameter name: method E mono : at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, System.Boolean throwOnBindFailure, System.Boolean allowClosed) <0x56d026b4 + 0x00d74> in :0 E mono : at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method) <0x56d03594 + 0x0001f> in :0 : at Android.Runtime.UncaughtExceptionHandler..cctor () <0x57d908a4 + 0x0003f> in :0 : --- End of inner exception stack trace --- : at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr) : at Android.Runtime.JNIEnv.Initialize (Android.Runtime.JnienvInitializeArgs* args)

-- 编辑

启用所有 AOT/LVVM/Concurrent 垃圾 collector/proguard/multidex 选项

-- 编辑 2

错误源代码:https://github.com/xamarin/xamarin-android/blob/master/src/Mono.Android/Android.Runtime/UncaughtExceptionHandler.cs

static UncaughtExceptionHandler ()
    {
        var mono_UnhandledException = typeof (System.Diagnostics.Debugger)
            .GetMethod ("Mono_UnhandledException", BindingFlags.NonPublic | BindingFlags.Static);
        mono_unhandled_exception = (Action<Exception>) Delegate.CreateDelegate (typeof(Action<Exception>), mono_UnhandledException);

        var ad_due = typeof (AppDomain)
            .GetMethod ("DoUnhandledException",
                bindingAttr:  BindingFlags.NonPublic | BindingFlags.Instance,
                binder:       null,
                types:        new []{typeof (UnhandledExceptionEventArgs)},
                modifiers:    null);
        if (ad_due != null) {
            AppDomain_DoUnhandledException  = (Action<AppDomain, UnhandledExceptionEventArgs>) Delegate.CreateDelegate (
                    typeof (Action<AppDomain, UnhandledExceptionEventArgs>), ad_due);
        }
    }

所以似乎 mono_UnhandledException 为空或 AppDomain_DoUnhandledException 为空。

将尝试在应用中心升级或降级单声道版本。应该是错的。

-- 编辑 3

AppDomain.cs 最近在单声道中发生了变化:

https://github.com/mono/mono/commits/c1cbe060f617707258fd5111fd5ffd7ccd581899/mcs/class/corlib/System/AppDomain.cs

但是DoUnhandledException没有改变。

-- 编辑 4

在本地 built/published 时工作正常。所以这个问题是appcenter特有的。

在我的例子中,问题是由于使用 App Center 尚不支持的 Android SDK 8.1 引起的。 我不得不降级到 SDK 8.0,现在构建工作正常。

App Center 团队承诺添加对 SDK 8.1 的支持,但他们还没有 ETA。

我们在使用 jenkins 和 msbuild 时遇到了同样的问题。回滚到 8.0 作为目标并禁用 'use latest' 工作。在本地,使用 'use latest',构建工具 26.0.3 和 msbuild 在 macOS 应用程序上工作就像一个魅力。不确定在 jenkins 上安装了什么构建工具。

我在 App Center 中遇到了同样的问题。我的 Android 应用程序设置为目标 android 8.1(最新)并且在 App Center 中构建正常但是当 运行 "launch test" 它失败。

该应用在调试和发布模式下在本地 运行 正常。

我尝试禁用启动测试,以便可以将应用程序分发给我的协作者。当我的任何合作者下载并使用该应用程序时,该应用程序无法运行。

我使用 VSTS 构建它并通过 App Center 分发给我的协作者,他们说该应用程序正在运行,所以我可以断定这是一个 App Center 构建问题。

我没有尝试使用 Android 8.0 构建我的应用程序,因为一些 nuget 包只能在 Android 8.1 上运行,我没有时间降级它们。

AppCenter最近发布了与Xamarin.Android8.2捆绑的Mono 5.8(支持TargetFrameworkVersion:8.1),为了使用它,请更改您的分支配置->Save&Build。

还有 filed the issue 供 Xamarin.Android 小组调查。