6

my xamarin android app, which was working fine, started to crash on each launch with this exception.

The app is built from appcenter's build service, as it always has. If i build it locally in Debug or Release mode, it launches fine. Using a device with Android 7.

Did anyone encountered this exception and knows what to do ?
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)

-- EDIT

All AOT/LVVM/Concurrent garbage collector/proguard/multidex options are enabled

-- EDIT 2

Source code of error: 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);
        }
    }

So it seems either mono_UnhandledException is null or AppDomain_DoUnhandledException is null.

Will try to upgrade or downgrade mono version in appcenter. It should be wrong.

-- EDIT 3

AppDomain.cs has changed recently in mono:

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

But DoUnhandledException has not changed.

-- EDIT 4

Works fine when built/published locally. So the problem is specific to appcenter.

Softlion
  • 12,281
  • 11
  • 58
  • 88

4 Answers4

1

In my case, the issue was caused by using Android SDK 8.1 which App Center doesn't support yet. I had to downgrade to SDK 8.0 and now build works fine.

App Center team promised to add support to SDK 8.1, but they don't have an ETA yet.

pfedotovsky
  • 711
  • 2
  • 10
  • 23
1

AppCenter has recently released Mono 5.8 bundled with Xamarin.Android 8.2 (which supports TargetFrameworkVersion: 8.1), in order to use it, please change your branch configuration -> Save&Build.

Also filed the issue for investigation by Xamarin.Android team.

nevalenny
  • 71
  • 6
0

we faced the same issue with jenkins and msbuild. rollback to 8.0 as target and disable 'use latest' works. locally, with 'use latest', build tools 26.0.3 and msbuild on macos app works like a charm. not sure what build tools installed on jenkins.

qwertylolman
  • 141
  • 1
  • 1
  • 8
0

I'm having the same issue in App Center. My Android app is set to target android 8.1 (latest) and builds ok in App Center but when running "launch test" it fails.

The app is running fine locally in Debug and Release modes.

I tried disabling launch test so the app can be distributed to my collaborators. When any of my collabortors download the app and use it, the app doesn't work.

I built it using VSTS and distributed through App Center to my collaborators and they said the app is working, so I can conclude it's an App Center build issue.

I didn't try to build my app using Android 8.0 because some nuget packages only work on Android 8.1 and I didn't have time to downgrade them.

Vackup
  • 652
  • 4
  • 11
  • I'm in the same boat as you. I just filed a report to the AppCenter team. In my case, my project is set to use the Mono 5.10.1 (Xamarin Android 8.3.3) and still I get this issue. I don't really want to set up a whole new build pipeline in VSTS to accommodate this problem. – Matthew Belk Aug 23 '18 at 16:20