Skip to content

[.NET 6] Debug build of Java.Interop.dll crashes Xamarin.Forms applications #5409

@jonathanpeppers

Description

@jonathanpeppers

Steps to Reproduce

  1. Build a Debug build of xamarin-android locally with msbuild Xamarin.Android.sln -t:PackDotNet or make pack-dotnet

  2. Build this Xamarin.Forms sample:

    ~\android-toolchain\dotnet\dotnet build .\HelloForms\HelloForms.csproj -t:Run -p:TargetFramework=net6.0-android

You may need to add an entry to NuGet.config, full path to:

<configuration>
  <packageSources>
    <add key="local" value="C:\src\xamarin-android\bin\BuildDebug\nupkgs" />
...
  1. The app crashes on startup.

Crashes with:

12-14 08:50:08.286 11868 11868 D app_process32: ---- DEBUG ASSERTION FAILED ----
12-14 08:50:08.286 11868 11868 D app_process32: ---- Assert Short Message ----
12-14 08:50:08.286 11868 11868 D app_process32: ManagedPeerType <=> JniTypeName Mismatch! javaVM.GetJniTypeInfoForType(typeof(Android.Views.LayoutInflaterInvoker)).JniTypeName="" != "android/view/LayoutInflater"
12-14 08:50:08.286 11868 11868 D app_process32: ---- Assert Long Message ----
12-14 08:50:08.286 11868 11868 D app_process32:
12-14 08:50:08.286 11868 11868 D app_process32:    at System.Diagnostics.DebugProvider.Fail(String message, String detailMessage)
12-14 08:50:08.286 11868 11868 D app_process32:    at System.Diagnostics.Debug.Fail(String message, String detailMessage)
12-14 08:50:08.286 11868 11868 D app_process32:    at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
12-14 08:50:08.286 11868 11868 D app_process32:    at System.Diagnostics.Debug.Assert(Boolean condition, String message)
12-14 08:50:08.286 11868 11868 D app_process32:    at Java.Interop.JniPeerMembers..ctor(String jniPeerTypeName, Type managedPeerType, Boolean checkManagedPeerType, Boolean isInterface)
12-14 08:50:08.286 11868 11868 D app_process32:    at Java.Interop.JniPeerMembers..ctor(String jniPeerTypeName, Type managedPeerType)
12-14 08:50:08.286 11868 11868 D app_process32:    at Android.Runtime.XAPeerMembers..ctor(String jniPeerTypeName, Type managedPeerType)
12-14 08:50:08.286 11868 11868 D app_process32:    at Android.Views.LayoutInflaterInvoker..cctor()
12-14 08:50:08.286 11868 11868 D app_process32:    at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstruct
12-14 08:50:08.290 11868 11868 W         : CLR: Managed code called FailFast, saying "ManagedPeerType <=> JniTypeName Mismatch! javaVM.GetJniTypeInfoForType(typeof(Android.Views.LayoutInflaterInvoker)).JniTypeName="" != "android/view/LayoutInflater"
12-14 08:50:08.290 11868 11868 W         :    at System.Diagnostics.DebugProvider.Fail(String message, String detailMessage)
12-14 08:50:08.290 11868 11868 W         :    at System.Diagnostics.Debug.Fail(String message, String detailMessage)
12-14 08:50:08.290 11868 11868 W         :    at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
12-14 08:50:08.290 11868 11868 W         :    at System.Diagnostics.Debug.Assert(Boolean condition, String message)
12-14 08:50:08.290 11868 11868 W         :    at Java.Interop.JniPeerMembers..ctor(String jniPeerTypeName, Type managedPeerType, Boolean checkManagedPeerType, Boolean isInterface)
12-14 08:50:08.290 11868 11868 W         :    at Java.Interop.JniPeerMembers..ctor(String jniPeerTypeName, Type managedPeerType)
12-14 08:50:08.290 11868 11868 W         :    at Android.Runtime.XAPeerMembers..ctor(String jniPeerTypeName, Type managedPeerType)
12-14 08:50:08.290 11868 11868 W         :    at Android.Views.LayoutInflaterInvoker..cctor()
12-14 08:50:08.290 11868 11868 W         :    at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo , Object , Object[] , Exception& )
12-14 08:50:08.290 11868 11868 W         :    at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, Object[] parameters, Boolean wrapExceptions)
12-14 08:50:08.290 11868 11868 W         :    at System.Reflection.RuntimeConstructorInfo.DoInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
12-14 08:50:08.290 11868 11868 W         :    at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
12-14 08:50:08.290 11868 11868 W         :    at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
12-14 08:50:08.290 11868 11868 W         :    at Java.Interop.TypeManager.CreateProxy(Type type, IntPtr handle, JniHandleOwnership transfer)
12-14 08:50:08.290 11868 11868 W         :    at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType)
12-14 08:50:08.290 11868 11868 W         :    at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type)
12-14 08:50:08.290 11868 11868 W         :    at Java.Lang.Object._GetObject[LayoutInflater](IntPtr handle, JniHandleOwnership transfer)
12-14 08:50:08.290 11868 11868 W         :    at Java.Lang.Object.GetObject[LayoutInflater](IntPtr handle, JniHandleOwnership transfer)
12-14 08:50:08.290 11868 11868 W         :    at Android.App.Activity.get_LayoutInflater()
12-14 08:50:08.290 11868 11868 W         :    at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnCreate(Bundle savedInstanceState, ActivationFlags flags)
12-14 08:50:08.290 11868 11868 W         :    at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnCreate(Bundle savedInstanceState)
12-14 08:50:08.290 11868 11868 W         :    at HelloForms.Droid.MainActivity.OnCreate(Bundle savedInstanceState)
12-14 08:50:08.290 11868 11868 W         :    at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState)
12-14 08:50:08.290 11868 11868 W         :    at Android.Runtime.DynamicMethodNameCounter.5(IntPtr , IntPtr , IntPtr )"
12-14 08:50:08.292 11868 11868 E mono    :
12-14 08:50:08.292 11868 11868 E mono    : Unhandled Exception:
12-14 08:50:08.292 11868 11868 E mono    : System.Diagnostics.DebugProvider+DebugAssertException: ManagedPeerType <=> JniTypeName Mismatch! javaVM.GetJniTypeInfoForType(typeof(Android.Views.LayoutInflaterInvoker)).JniTypeName="" != "android/view/LayoutInflater"
12-14 08:50:08.292 11868 11868 E mono    :    at System.Diagnostics.DebugProvider.Fail(String message, String detailMessage)
12-14 08:50:08.292 11868 11868 E mono    :    at System.Diagnostics.Debug.Fail(String message, String detailMessage)
12-14 08:50:08.292 11868 11868 E mono    :    at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
12-14 08:50:08.292 11868 11868 E mono    :    at System.Diagnostics.Debug.Assert(Boolean condition, String message)
12-14 08:50:08.292 11868 11868 E mono    :    at Java.Interop.JniPeerMembers..ctor(String jniPeerTypeName, Type managedPeerType, Boolean checkManagedPeerType, Boolean isInterface)
12-14 08:50:08.292 11868 11868 E mono    :    at Java.Interop.JniPeerMembers..ctor(String jniPeerTypeName, Type managedPeerType)
12-14 08:50:08.292 11868 11868 E mono    :    at Android.Runtime.XAPeerMembers..ctor(String jniPeerTypeName, Type managedPeerType)
12-14 08:50:08.292 11868 11868 E mono    :    at Android.Views.LayoutInflaterInvoker..cctor()
12-14 08:50:08.292 11868 11868 E mono    :    at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo , Object , Object[] , Exception& )
12-14 08:50:08.292 11868 11868 E mono    :    at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, Object[] parameters, Boolean wrapExceptions)
12-14 08:50:08.292 11868 11868 E mono    :    at System.Reflection.RuntimeConstructorInfo.DoInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
12-14 08:50:08.292 11868 11868 E mono    :    at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
12-14 08:50:08.292 11868 11868 E mono    :    at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
12-14 08:50:08.292 11868 11868 E mono    :    at Java.Interop.TypeManager.CreateProxy(Type type, IntPtr handle, JniHandleOwnership transfer)
12-14 08:50:08.292 11868 11868 E mono    :    at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType)
12-14 08:50:08.292 11868 11868 E mono    :    at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type)
12-14 08:50:08.292 11868 11868 E mono    :    at Java.Lang.Object._GetObject[LayoutInflater](IntPtr handle, JniHandleOwnership transfer)
12-14 08:50:08.292 11868 11868 E mono    :    at Java.Lang.Object.GetObject[LayoutInflater](IntPtr handle, JniHandleOwnership transfer)
12-14 08:50:08.292 11868 11868 E mono    :    at Android.App.Activity.get_LayoutInflater()
12-14 08:50:08.292 11868 11868 E mono    :    at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnCreate(Bundle savedInstanceState, ActivationFlags flags)
12-14 08:50:08.292 11868 11868 E mono    :    at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnCreate(Bundle savedInstanceState)
12-14 08:50:08.292 11868 11868 E mono    :    at HelloForms.Droid.MainActivity.OnCreate(Bundle savedInstanceState)
12-14 08:50:08.292 11868 11868 E mono    :    at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState)
12-14 08:50:08.292 11868 11868 E mono    :    at Android.Runtime.DynamicMethodNameCounter.5(IntPtr , IntPtr , IntPtr )

This works if you have a Release build of Java.Interop.dll because this assertion is stripped away:

https://github.com/xamarin/java.interop/blob/2f62ffd4367870802f146c7957a94839daf1b86d/src/Java.Interop/Java.Interop/JniPeerMembers.cs#L27-L34

We think there must be some issue with type maps in this project?

We probably won't be able to look into this until January, so I thought I'd post this so we don't forget.

Metadata

Metadata

Assignees

Labels

Area: App RuntimeIssues in `libmonodroid.so`.Area: App+Library BuildIssues when building Library projects or Application projects.bugComponent does not function as intended.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions