'Android.Runtime.UncaughtExceptionHandler'的类型初始值设定项引发了异常

问题描述 投票:6回答:4

我的xamarin安卓应用程序运行正常,每次启动都会因此异常而崩溃。

该应用程序是从appcenter的构建服务构建的,一如既往。如果我在Debug或Release模式下在本地构建它,它会正常启动。使用Android 7设备。

有没有人遇到这个例外,知道该怎么办? Ty!

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 /并发垃圾收集器/ 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为null或AppDomain_DoUnhandledException为null。

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

- 编辑3

AppDomain.cs最近改为单声道:

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

但是DoUnhandledException没有改变。

- 编辑4

在本地构建/发布时工作正常。所以问题是appcenter特有的。

xamarin.android mono visual-studio-app-center
4个回答
1
投票

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

另外filed the issue由Xamarin.Android团队进行调查。


1
投票

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

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


0
投票

我们遇到了与jenkins和msbuild相同的问题。作为目标回滚到8.0并禁用“使用最新”工作。在本地,使用'使用最新',构建工具26.0.3和macos app上的msbuild就像一个魅力。不确定jenkins上安装的构建工具。


0
投票

我在App Center中遇到了同样的问题。我的Android应用程序设置为目标Android 8.1(最新)并在App Center中构建正常但在运行“启动测试”时它失败。

该应用程序在调试和发布模式下本地运行良好。

我尝试禁用启动测试,以便将应用分发给我的协作者。当我的任何协作者下载应用程序并使用它时,该应用程序不起作用。

我使用VSTS构建它并通过App Center分发给我的协作者,他们说应用程序正在运行,因此我可以得出结论,这是App Center构建问题。

我没有尝试使用Android 8.0构建我的应用程序,因为一些nuget软件包仅适用于Android 8.1,我没有时间降级它们。

© www.soinside.com 2019 - 2024. All rights reserved.