Bug 56121 - No constructor found for Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)
Summary: No constructor found for Xamarin.Forms.Platform.Android.AppCompat.MasterDetai...
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jimmy [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-05-09 03:54 UTC by Kent
Modified: 2018-01-16 20:34 UTC (History)
5 users (show)

Tags: android crash masterdetailpage
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Kent 2017-05-09 03:54:06 UTC
At risk of being asked for more info (I don't really have it), or for a simple repro (some problems are actually hard to repro), I received this crash report for my project:

Message: [NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer from native handle 0x7fd0b871b4 (key_handle 0x1f0aca5).]
 Java.Interop.TypeManager.CreateInstance(System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) in <e83e7f38cb2c4d3ea5229a48ee53517a>:0
 Java.Lang.Object.GetObject(System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) in <e83e7f38cb2c4d3ea5229a48ee53517a>:0
 Java.Lang.Object._GetObject[T](System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) in <e83e7f38cb2c4d3ea5229a48ee53517a>:0
 Java.Lang.Object.GetObject[T](System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) in <e83e7f38cb2c4d3ea5229a48ee53517a>:0
 Java.Lang.Object.GetObject[T](System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) in <e83e7f38cb2c4d3ea5229a48ee53517a>:0
 Android.Support.V4.Widget.DrawerLayout.n_OnDetachedFromWindow(System.IntPtr jnienv, System.IntPtr native__this) in <c3d50e54153646b9a90aea2bbeede7ad>:0
    (wrapper dynamic-method) System.Object:e7229481-4a78-477a-bd95-1c07f2e84794 (intptr,intptr)
Message: [MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)]
 Java.Interop.TypeManager.CreateProxy(System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) in <e83e7f38cb2c4d3ea5229a48ee53517a>:0
 Java.Interop.TypeManager.CreateInstance(System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) in <e83e7f38cb2c4d3ea5229a48ee53517a>:0
Message: [Exception of type 'Java.Interop.JavaLocationException' was thrown.]
 Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.
    --- End of managed Java.Lang.Error stack trace ---
 java.lang.Error: Java callstack:
 md5270abb39e60627f0f200893b490a1ade.MasterDetailPageRenderer.n_onDetachedFromWindow(Native Method):0
 md5270abb39e60627f0f200893b490a1ade.MasterDetailPageRenderer.onDetachedFromWindow(MasterDetailPageRenderer.java:60):0
 android.view.View.dispatchDetachedFromWindow(View.java:16684):0
 android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3426):0
 android.view.ViewGroup.removeAllViewsInLayout(ViewGroup.java:5151):0
 android.view.ViewGroup.removeAllViews(ViewGroup.java:5097):0
 md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.n_onDestroy(Native Method):0
 md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.onDestroy(FormsAppCompatActivity.java:81):0
 android.app.Activity.performDestroy(Activity.java:7165):0
 android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1161):0
 android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4626):0
 android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4662):0
 android.app.ActivityThread.-wrap7(ActivityThread.java):0
 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1711):0
 android.os.Handler.dispatchMessage(Handler.java:102):0
 android.os.Looper.loop(Looper.java:154):0
 android.app.ActivityThread.main(ActivityThread.java:6688):0
 java.lang.reflect.Method.invoke(Native Method):0
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468):0
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358):0

Looking at the source, that constructor does indeed appear to be missing.
Comment 1 Jimmy [MSFT] 2017-05-09 17:04:27 UTC
Hey Kent, this sounds like an issue between the native and managed renderer objects, similar to what Jason mentioned in another report: https://bugzilla.xamarin.com/show_bug.cgi?id=39189#c5

This answer on SO might also shed some more light on this kind of scenario: http://stackoverflow.com/a/10603714/6457998

In your case, this seems like it's happening when the Activity is being destroyed as indicated by the stack trace. What's potentially happening is the Java-side is invoking a method on the managed renderer object that has already been disposed, so it tries to create a new instance of it but can't because of the missing the (IntPtr, JniHandleOwnership) constructor. 

While adding the constructor should prevent the exception from being thrown, what we probably want to do is avoid this scenario from happening in the first place. Unfortunately without a reliable reproduction, it's difficult to determine if this is being caused by the project, Xamarin.Forms, or Xamarin.Android. 

This may also be device or Android version specific which could make reproducing this more difficult. Do you know what device and Android version the report came from? How frequently is this crash being reported?
Comment 2 Kent 2017-05-09 23:45:11 UTC
Thanks for the reply Jimmy.

It's hard to get a good sense of frequency yet because we've only recently gone to the store. Since then, we've seen this crash 4 times, but never saw it beforehand.

In all cases, the device is a Samsung, but we've seen different combinations of models and hardware specs:

 - SM-G955F (arm64-v8a with 16MB physical memory, 5MB available, running OS version 24)
 - SM-G930F (arm64-v8a with 23MB physical memory, 6MB available, running OS version 24)
 - SM-G930F (arm64-v8a with 30MB physical memory, 10MB available, running OS version 24)
Comment 3 Samantha Houts [MSFT] 2017-07-05 23:11:09 UTC
Thank you for the additional information, Kent. Since we don't have a reproduction that we can work against, we'll go ahead and close this report for now, but if you or anyone else can figure out a reliable way to reproduce the issue, please feel free to reopen this ticket.

Thank you!
Comment 4 Jason Rai 2018-01-16 20:34:28 UTC
This is happening to me inconsistently on Xamarin Forms 2.5.0.121934.

PRIV on 6.0.1 and Moto Z Play 7.1.1.

Xamarin Exception Stack:
System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer from native handle 0xbeb054dc (key_handle 0x2623a70).
  at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x0017d] in <3169d8ea81d6481d8eef090af0a62710>:0
  at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000b9] in <3169d8ea81d6481d8eef090af0a62710>:0
  at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <3169d8ea81d6481d8eef090af0a62710>:0
  at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <3169d8ea81d6481d8eef090af0a62710>:0
  at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in <3169d8ea81d6481d8eef090af0a62710>:0
  at Android.Views.View.n_OnDetachedFromWindow (System.IntPtr jnienv, System.IntPtr native__this) [0x00000] in <3169d8ea81d6481d8eef090af0a62710>:0
  at (wrapper dynamic-method) System.Object:daa99c49-4d70-4202-aa1a-5f9021584a1e (intptr,intptr)
--- End of inner exception stack trace ---
  System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)
    at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00054] in <3169d8ea81d6481d8eef090af0a62710>:0
    at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in <3169d8ea81d6481d8eef090af0a62710>:0
  --- End of inner exception stack trace ---
    Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
      at Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.
      at java.lang.Error: Java callstack:
      at md5270abb39e60627f0f200893b490a1ade.MasterDetailPageRenderer.n_onDetachedFromWindow(Native Method)
      at md5270abb39e60627f0f200893b490a1ade.MasterDetailPageRenderer.onDetachedFromWindow(MasterDetailPageRenderer.java:60)
      at android.view.View.dispatchDetachedFromWindow(View.java:15576)
      at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3190)
      at android.view.ViewGroup.removeAllViewsInLayout(ViewGroup.java:4914)
      at android.view.ViewGroup.removeAllViews(ViewGroup.java:4860)
      at android.support.v7.app.AlertDialog_IDialogInterfaceOnClickListenerImplementor.n_onClick(Native Method)
      at android.support.v7.app.AlertDialog_IDialogInterfaceOnClickListenerImplementor.onClick(AlertDialog_IDialogInterfaceOnClickListenerImplementor.java:30)
      at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:162)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:154)
      at android.app.ActivityThread.main(ActivityThread.java:6165)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)