【问题标题】:The type initializer for 'Android.Runtime.UncaughtExceptionHandler' threw an exception'Android.Runtime.UncaughtExceptionHandler' 的类型初始化程序引发了异常
【发布时间】:2018-03-09 07:34:43
【问题描述】:

我的 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/并发垃圾收集器/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 最近在 mono 中发生了变化:

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

但是 DoUnhandledException 没有改变。

-- 编辑 4

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

【问题讨论】:

  • 我们也遇到了这个问题。我们在 iOS 上没有遇到任何问题。我们还在启动应用程序时的日志中发现了这一点:03-09 09:51:44.841: W/OpenGLRenderer(2455): 在视图上错误地调用 buildLayer: ShortcutAndWidgetContainer, 破坏层...
  • 是的,仅适用于 Android。一些用户也报告了这个问题,但直到现在它都无法重现。
  • 我们也会遇到类似的问题。
  • 同样的问题,我已经报告给应用中心帮助
  • 有人有更新吗?对我来说同样的问题,降级到 8.0 对我不起作用。

标签: xamarin.android mono visual-studio-app-center


【解决方案1】:

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

另外filed the issue 供 Xamarin.Android 团队调查。

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 这很有趣。会检查的。
    • @Softlion 这对你有用吗?我有同样的问题,无法找到解决方案。降级到 8.0 似乎不起作用。
    【解决方案3】:

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

    【讨论】:

      【解决方案4】:

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

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

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

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

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

      【讨论】:

      • 我和你在同一条船上。我刚刚向 AppCenter 团队提交了一份报告。就我而言,我的项目设置为使用 Mono 5.10.1 (Xamarin Android 8.3.3),但我仍然遇到这个问题。我真的不想在 VSTS 中建立一个全新的构建管道来解决这个问题。
      猜你喜欢
      • 1970-01-01
      • 2021-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-28
      • 1970-01-01
      • 2016-03-27
      • 1970-01-01
      相关资源
      最近更新 更多