Xamarin.forms: [Android] Unable to activate instance of type LabelRenderer from native handle

Created on 12 Apr 2018  路  29Comments  路  Source: xamarin/Xamarin.Forms

Bug from Bugzilla 57802 https://bugzilla.xamarin.com/show_bug.cgi?id=57802

Description

The following exception is sometimes thrown:

Xamarin Exception Stack:
System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer from native handle 0xd5a00019 (key_handle 0x422e3928).
  at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x0017d] in <6b2c8a4c9b5042628fe9e4e3934c956b>:0
  at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000b9] in <6b2c8a4c9b5042628fe9e4e3934c956b>:0
  at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <6b2c8a4c9b5042628fe9e4e3934c956b>:0
  at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <6b2c8a4c9b5042628fe9e4e3934c956b>:0
  at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in <6b2c8a4c9b5042628fe9e4e3934c956b>:0
  at Android.Views.View.n_Invalidate (System.IntPtr jnienv, System.IntPtr native__this) [0x00000] in <6b2c8a4c9b5042628fe9e4e3934c956b>:0
  at (wrapper dynamic-method) System.Object.105d7a52-232b-4de3-a617-9aedddf0a7ca(intptr,intptr)
--- End of inner exception stack trace ---
  System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)
    at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00054] in <6b2c8a4c9b5042628fe9e4e3934c956b>:0
    at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in <6b2c8a4c9b5042628fe9e4e3934c956b>: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 md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsTextView.n_invalidate(Native Method)
      at md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsTextView.invalidate(FormsTextView.java:45)
      at android.view.ViewRootImpl$InvalidateOnAnimationRunnable.run(ViewRootImpl.java:6552)
      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
      at android.view.Choreographer.doCallbacks(Choreographer.java:591)
      at android.view.Choreographer.doFrame(Choreographer.java:559)
      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
      at android.os.Handler.handleCallback(Handler.java:808)
      at android.os.Handler.dispatchMessage(Handler.java:103)
      at android.os.Looper.loop(Looper.java:193)
      at android.app.ActivityThread.main(ActivityThread.java:5299)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:515)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:830)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:646)
      at dalvik.system.NativeStart.main(Native Method)

It seems to revolve around a missing constructor LabelRenderer(IntPtr javaReference, JniHandleOwnership transfer). That constructor does exist on the base class FormsTextView, but is protected.

Steps to Reproduce

I don't have any, I'm depending on App Center crash logs. The linked bugzilla ticket claims to have a reproducible case https://bugzilla.xamarin.com/attachment.cgi?id=23223 . It seems it may be device dependent so my main reason for posting this is to list the devices that are apparently having the issue for me (as requested in the last comment on Bugzilla):

LG G Pad X2 8.0 PLUS - 7.0
PLAY Club - 4.4.2
Galaxy Core Prime - 4.4.4
Galaxy On Nxt - 7.0
Galaxy J3(2016) - 5.1.1
Galaxy J7 Neo - 7.0
Galaxy Tab3V 7.0 - 4.4.0

Basic Information

  • Version with issue: 2.5.1.340284-pre2 (plus others in the bugzilla ticket)
  • Platform Target Frameworks:

    • Android 8.1

  • Android Support Library Version: 26.0.2
  • Affected Devices:
Android: 7.0
Android Build: NRD90U
Manufacturer: LGE
Model: LG-V530

Android: 4.4.2
Android Build: KOT49H
Manufacturer: StarMobile
Model: PLAY Club

Android: 4.4.4
Android Build: KTU84P
Manufacturer: samsung
Model: SM-G360P

Android: 7.0
Android Build: NRD90M
Manufacturer: samsung
Model: SM-G610F

Android: 5.1.1
Android Build: LMY47V
Manufacturer: samsung
Model: SM-J320FN

Android: 7.0
Android Build: NRD90M
Manufacturer: samsung
Model: SM-J701F

Android: 4.4.4
Android Build: KTU84P
Manufacturer: samsung
Model: SM-T113NU

Reproduction Link

Someone else suggested this https://bugzilla.xamarin.com/attachment.cgi?id=23223

8 high inactive Android bug

Most helpful comment

Still this happens in v 4.0.0.482894. No custom renderers. Multi-Dex enabled and Target Platform is 28

All 29 comments

I got this issue on Android by rendering multiple Labels.

I'm seeing the same issue with Xamarin.Forms version 3.1.0.637273 (all of the android support libraries being at version 27.0.2.1).

Are there any estimations on when this problem might be fixed?

I'm not sure if this is relevant and/or useful but here is the debug output that I got:

System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer from native handle 0x7fff2e1024 (key_handle 0xdfd9ae3).

Thread finished: #22
The thread 0x16 has exited with code 0 (0x0).
Thread started: #29
Thread started: #30
Thread started: #31
Thread started: #32
Thread started: #33
Thread started: #34
Thread started: #35
Thread started: #36
07-23 11:02:01.826 D/Mono (14000): DllImport attempting to load: '/system/lib64/liblog.so'.
07-23 11:02:01.828 D/Mono (14000): DllImport loaded library '/system/lib64/liblog.so'.
07-23 11:02:01.829 D/Mono (14000): DllImport searching in: '/system/lib64/liblog.so' ('/system/lib64/liblog.so').
07-23 11:02:01.829 D/Mono (14000): Searching for '__android_log_print'.
07-23 11:02:01.829 D/Mono (14000): Probing '__android_log_print'.
07-23 11:02:01.829 D/Mono (14000): Found as '__android_log_print'.
Thread started: #37
07-23 11:02:01.851 I/MonoDroid(14000): UNHANDLED EXCEPTION:
07-23 11:02:01.885 I/MonoDroid(14000): System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer from native handle 0x7fff2e1024 (key_handle 0xdfd9ae3). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
07-23 11:02:01.885 I/MonoDroid(14000): --- End of inner exception stack trace ---
07-23 11:02:01.885 I/MonoDroid(14000): at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00035] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:303
07-23 11:02:01.885 I/MonoDroid(14000): at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:281
07-23 11:02:01.885 I/MonoDroid(14000): --- End of inner exception stack trace ---
07-23 11:02:01.885 I/MonoDroid(14000): at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00153] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:288
07-23 11:02:01.885 I/MonoDroid(14000): at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000b9] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:467
07-23 11:02:01.885 I/MonoDroid(14000): at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:438
07-23 11:02:01.885 I/MonoDroid(14000): at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:430
07-23 11:02:01.885 I/MonoDroid(14000): at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:424
07-23 11:02:01.885 I/MonoDroid(14000): at Android.Views.View.n_Invalidate (System.IntPtr jnienv, System.IntPtr native__this) [0x00000] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/obj/Release/android-27/mcw/Android.Views.View.cs:14780
07-23 11:02:01.885 I/MonoDroid(14000): at (wrapper dynamic-method) System.Object.a2b894d3-b4a1-432c-9d5f-4c052e6421ce(intptr,intptr)
07-23 11:02:01.913 W/art (14000): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
07-23 11:02:01.916 D/Mono (14000): DllImport searching in: '__Internal' ('(null)').
07-23 11:02:01.916 D/Mono (14000): Searching for 'java_interop_jnienv_throw'.
07-23 11:02:01.916 D/Mono (14000): Probing 'java_interop_jnienv_throw'.
07-23 11:02:01.916 D/Mono (14000): Found as 'java_interop_jnienv_throw'.
An unhandled exception occured.

07-23 11:02:02.698 E/mono (14000):
07-23 11:02:02.698 E/mono (14000): Unhandled Exception:
07-23 11:02:02.698 E/mono (14000): System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer from native handle 0x7fff2e1024 (key_handle 0xdfd9ae3). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
07-23 11:02:02.698 E/mono (14000): --- End of inner exception stack trace ---
07-23 11:02:02.698 E/mono (14000): at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00035] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:303
07-23 11:02:02.698 E/mono (14000): at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:281
07-23 11:02:02.698 E/mono (14000): --- End of inner exception stack trace ---
07-23 11:02:02.698 E/mono (14000): at (wrapper dynamic-method) System.Object.a2b894d3-b4a1-432c-9d5f-4c052e6421ce(intptr,intptr)
07-23 11:02:02.702 E/mono-rt (14000): [ERROR] FATAL UNHANDLED EXCEPTION: System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer from native handle 0x7fff2e1024 (key_handle 0xdfd9ae3). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
07-23 11:02:02.702 E/mono-rt (14000): --- End of inner exception stack trace ---
07-23 11:02:02.702 E/mono-rt (14000): at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00035] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:303
07-23 11:02:02.702 E/mono-rt (14000): at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:281
07-23 11:02:02.702 E/mono-rt (14000): --- End of inner exception stack trace ---
07-23 11:02:02.702 E/mono-rt (14000): at (wrapper dynamic-method) System.Object.a2b894d3-b4a1-432c-9d5f-4c052e6421ce(intptr,intptr)
07-23 11:02:02.730 E/GLConsumer(14000): ~EglImage: eglDestroyImageKHR failed
07-23 11:02:02.732 E/GLConsumer(14000): ~EglImage: eglDestroyImageKHR failed
07-23 11:02:02.737 E/GLConsumer(14000): ~EglImage: eglDestroyImageKHR failed
07-23 11:02:03.018 I/TMSDISP (14000): AcsAndroidVirtualDisplayIntfImpl::~AcsAndroidVirtualDisplayIntfImpl - Enter
07-23 11:02:03.018 I/TMSDISP (14000): AcsAndroidVirtualDisplayIntfImpl::~AcsAndroidVirtualDisplayIntfImpl - Enter2
07-23 11:02:03.018 I/TMSDISP (14000): AcsAndroidVirtualDisplayIntfImpl::~AcsAndroidVirtualDisplayIntfImpl - mSource2
07-23 11:02:03.018 I/TMSDISP (14000): AcsAndroidVirtualDisplayIntfImpl::~AcsAndroidVirtualDisplayIntfImpl - Exit

FYI @nickrandolph

I am not sure if this is the right place to weigh in however I am seeing a very similar issue. I don't always see the crash with the same control however whenever our app goes in to the background for some time and then returns we see a crash and the error reported points to any one of our customer renderers that inherit from the Android ones and the missing constructor expecting an IntPtr and Android.Runtime.JniHandleOwnership.

I noticed in the source that controls themselves expect these parameters not the renderers.

We are experiencing this in our application as well. Have not been able to create a reproduction case. We have updated to latest forms pre-release package (3.2.0.729530-pre2) and users are still hitting this intermittently. This is an example crash from AppCenter:

System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.LabelRenderer from native handle 0xbed6253c (key_handle 0x5ab29e5). at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x0017d] in <2b979c0925674429959c0292859a40f2>:0 at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000b9] in <2b979c0925674429959c0292859a40f2>:0 at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <2b979c0925674429959c0292859a40f2>:0 at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <2b979c0925674429959c0292859a40f2>:0 at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in <2b979c0925674429959c0292859a40f2>:0 at Android.Views.View.n_DispatchTouchEvent_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_e) [0x00000] in <2b979c0925674429959c0292859a40f2>:0 at (wrapper dynamic-method) System.Object.bed3e0bc-80b0-47a7-892d-2b941800ec58(intptr,intptr,intptr) --- End of inner exception stack trace --- System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.LabelRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00054] in <2b979c0925674429959c0292859a40f2>:0 at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in <2b979c0925674429959c0292859a40f2>: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 md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.n_dispatchTouchEvent(Native Method) at md51558244f76c53b6aeda52c8a337f2c37.VisualElementRenderer_1.dispatchTouchEvent(VisualElementRenderer_1.java:64) at android.view.ViewGroup.cancelTouchTarget(ViewGroup.java:2600) at android.view.ViewGroup.removeAllViewsInLayout(ViewGroup.java:4672) at android.view.ViewGroup.removeAllViews(ViewGroup.java:4623) at md58432a647068b097f9637064b8985a5e0.FragmentContainer.n_onDestroyView(Native Method) at md58432a647068b097f9637064b8985a5e0.FragmentContainer.onDestroyView(FragmentContainer.java:41) at android.support.v4.app.Fragment.performDestroyView(Fragment.java:2480) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1422) at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1569) at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:753) at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2415) at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2201) at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2155) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2064) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:718) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5951) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

@jordan-surveycom while this is a horrible workaround we have so far not seen any crashes in the field. We used the approach as detailed in this post:

https://forums.xamarin.com/discussion/comment/342986#Comment_342986

Essentially it involves in creating the constructor that the stack trace is complaining about in each of our Custom renderers. The horrible part is it brings in warnings in the Android build because the default constructor has been marked as obsolete from version 2.5 of Xamarin Forms.

I do hope they resolve it soon!

@bijington Thanks for suggestion. I thought it may have fixed the issue for us, but unfortunately our users are still hitting it even after adding the constructor to each of our custom renderers.

Still this happens in v 4.0.0.482894. No custom renderers. Multi-Dex enabled and Target Platform is 28

Same issue as @consoleit . Still happening in v4.0.0.482894 and have to enable legacy, Forms.SetFlags("UseLegacyRenderers"), to stop the exception.

Same issue when I try removing item from grid, while using bindinglayout

CrashEntryAndroid.zip
Easy to reproduce with the attached project on Android 4.3 :

Run the solution
Click on the menu "About"
There is the crash : Unable to activate instance of type Xamarin.Forms.Platform.Android.FormsEditText from native handle

I found a work around:
[assembly: ExportRenderer(typeof(Entry), typeof(MyEntryRenderer))]
namespace CrashEntryAndroid.Droid
{
public class MyEntryRenderer : EntryRenderer
{
public MyEntryRenderer(Context context) : base(context)
{

    }

    protected override FormsEditText CreateNativeControl()
    {
        return new MyFormsEditText(Context);
    }


}

public class MyFormsEditText : FormsEditText
{
    public MyFormsEditText(Context context) : base(context)
    {

    }

    //Android 4.3 - to avoid this crash : Unable to activate instance of type Xamarin.Forms.Platform.Android.FormsEditText        
    public MyFormsEditText(System.IntPtr i, Android.Runtime.JniHandleOwnership j) : base(Forms.Context)
    {

    }
}

}

The workout provide by @MereDoku worked for me. For quick reference, here is the label renderer.

`[assembly:ExportRenderer(typeof(CustomLabel), typeof(CustomLabelRenderer))]
namespace MyNamespace.Mobile.Droid.Renderers
{

public class CustomLabelRenderer : LabelRenderer
{
    public CustomLabelRenderer(Context context) : base(context)
    {

    }

    public CustomLabelRenderer(System.IntPtr i, Android.Runtime.JniHandleOwnership j) : base(Forms.Context)
    {

    }
}

}`

@MereDoku Thanks for the repro, I try to fix all the dispose issues on Android, and when I have a repro I can test it.

From the repro the stack trace is :

0x8 in Java.Lang.Object.GetObject<Android.Widget.TextView>
0x3 in Android.Widget.TextView.n_OnSelectionChanged_II
0x1 in Xamarin.Forms.Platform.Android.FragmentManagerExtensions.ExecutePendingTransactionsEx at D:\a\1\s\Xamarin.Forms.Platform.Android\Extensions\FragmentManagerExtensions.cs:42,4
0x299 in Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.Dispose at D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:265,7
0x11 in Xamarin.Forms.Platform.Android.MasterDetailContainer.DisposeChildRenderers at D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\MasterDetailContainer.cs:114,4
0x19 in Xamarin.Forms.Platform.Android.MasterDetailContainer.set_ChildView at D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\MasterDetailContainer.cs:40,6
0x33 in Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer.<UpdateDetail>g__Update|79_0 at D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\MasterDetailPageRenderer.cs:407,5

So the issue is either is the MasterDetailPageRenderer.Update or in the LabelRenderer.Dispose.

The good news is that the first issue is fixed by #4955 and the second by #6467 and the fixes are included in the next Xamarin Forms version (the first preview version is already available on nuget).

I still have tested myself and I confirm that I doesn't reproduce the issue on Android 4.3 with Xamarin Forms 4.2-pre1.

@kvpt can you confirm that this issue is (or should be) fixed with your PRs?

I can confirm the issue doesn't occur on MereDoku reproduction with my fixs applied.
I not tested with one fix only but I think from the stacktrace it's #4955 which fixed the issue.
For the original case it should be fixed by #6467.

Great. I will close this one then. If the issue still occurs, please feel free to reopen it.

@kvpt could I kindly ask you to have a look at the latest comments in #7289. It seems to be a similar issue, but I can't quite figure out what is going on. With your experience with this now, you might be able to see what is going on :) Thanks!

@jfversluis @kvpt Are these changes in the 4.2 release? We are still seeing exceptions coming in to AppCenter after updating to v4.2.0.709249 of Xamarin.Forms. I can try to create a reproduction case.

Xamarin Exception Stack: System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer from native handle 0x7fd00d02c4 (key_handle 0x7315747). at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00182] in <86a0fa5f53ea41558adc9c3b4b8e826c>:0 at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000c1] in <86a0fa5f53ea41558adc9c3b4b8e826c>:0 at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <86a0fa5f53ea41558adc9c3b4b8e826c>:0 at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <86a0fa5f53ea41558adc9c3b4b8e826c>:0 at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in <86a0fa5f53ea41558adc9c3b4b8e826c>:0 at Android.Views.View.n_Invalidate (System.IntPtr jnienv, System.IntPtr native__this) [0x00000] in <86a0fa5f53ea41558adc9c3b4b8e826c>:0 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.73(intptr,intptr) --- End of inner exception stack trace --- System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00055] in <86a0fa5f53ea41558adc9c3b4b8e826c>:0 at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00116] in <86a0fa5f53ea41558adc9c3b4b8e826c>: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 md51558244f76c53b6aeda52c8a337f2c37.FormsTextView.n_invalidate(Native Method) at md51558244f76c53b6aeda52c8a337f2c37.FormsTextView.invalidate(FormsTextView.java:45) at android.view.ViewRootImpl$InvalidateOnAnimationRunnable.run(ViewRootImpl.java:8690) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949) at android.view.Choreographer.doCallbacks(Choreographer.java:761) at android.view.Choreographer.doFrame(Choreographer.java:693) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7124) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)

@jordan-surveycom My changes are included in 4.2 release.
I think it fix somes cases of crash like this but not all.
If you compare your stacktrace, they are different so it's the same result but not the same root cause.
I modified the code to unsubscribe the event first to ensure that any events triggered during dispose don't cause a crash like this, but it's still possible that an event handler was in execution during the dispose and execute slowly and compete with the dispose method and cause crash.

If you can give us a reproduction it will be perfect, but from experience it's very difficult to make one because these crashs are the result of some race condition.

I also remarked a strange behavior with dispose on certain cases https://github.com/xamarin/Xamarin.Forms/pull/7163#issuecomment-521870112, I think it can be related. I will try to test that ASAP.

@kvpt Yes, I believe I have attempted to reproduce this before without any luck. Thanks for the response. If I am able to reproduce, I will provide it to guys.

One of my customers experiencing this issue.
Xamarin.Forms 4.2.0.848062
HUAWEI DRA-LX5 Android 8.1.0

I have no Label custom renderers.
The stack trace appears to be identical to original bug poster.

System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer from native handle 0xbe9f7d2c (key_handle 0xf4cf345). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
   --- End of inner exception stack trace ---
  at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) <0x898b3960 + 0x001dc> in <c14bfdebec884e21b2ed91bef9f720c2>:0 
  at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) <0x898b32d0 + 0x00333> in <c14bfdebec884e21b2ed91bef9f720c2>:0 
   --- End of inner exception stack trace ---
  at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) <0x898b32d0 + 0x0065c> in <c14bfdebec884e21b2ed91bef9f720c2>:0 
  at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) <0x898afb70 + 0x00383> in <c14bfdebec884e21b2ed91bef9f720c2>:0 
  at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) <0x898afaac + 0x0007f> in <c14bfdebec884e21b2ed91bef9f720c2>:0 
  at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) <0x898afa14 + 0x0006f> in <c14bfdebec884e21b2ed91bef9f720c2>:0 
  at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) <0x898af970 + 0x0007b> in <c14bfdebec884e21b2ed91bef9f720c2>:0 
  at Android.Views.View.n_Invalidate (System.IntPtr jnienv, System.IntPtr native__this) [0x00000] in <c14bfdebec884e21b2ed91bef9f720c2>:0 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.43(intptr,intptr)
System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer from native handle 0xbe9f7d2c (key_handle 0xf4cf345). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
   --- End of inner exception stack trace ---
  at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) <0x898b3960 + 0x001dc> in <c14bfdebec884e21b2ed91bef9f720c2>:0 
  at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) <0x898b32d0 + 0x00333> in <c14bfdebec884e21b2ed91bef9f720c2>:0 
   --- End of inner exception stack trace ---
  at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) <0x898b32d0 + 0x0065c> in <c14bfdebec884e21b2ed91bef9f720c2>:0 
  at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) <0x898afb70 + 0x00383> in <c14bfdebec884e21b2ed91bef9f720c2>:0 
  at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) <0x898afaac + 0x0007f> in <c14bfdebec884e21b2ed91bef9f720c2>:0 
  at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) <0x898afa14 + 0x0006f> in <c14bfdebec884e21b2ed91bef9f720c2>:0 
  at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) <0x898af970 + 0x0007b> in <c14bfdebec884e21b2ed91bef9f720c2>:0 
  at Android.Views.View.n_Invalidate (System.IntPtr jnienv, System.IntPtr native__this) [0x00000] in <c14bfdebec884e21b2ed91bef9f720c2>:0 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.43(intptr,intptr)

Same here on Xamarin.Forms 4.2.0.848062
So far only on Huawei P10 lite - Android 7.0

We have a CustomLaberRender like below. We have implemented solutions with adding additional constructors and setting Forms.SetFlags("UseLegacyRenderers");. Will be monitoring if this helps.
`
[assembly: ExportRenderer(typeof(CustomLabel), typeof(CustomLabelRenderer))]
namespace App.Droid
{
class CustomLabelRenderer : LabelRenderer
{
public CustomLabelRenderer(Context context) : base(context)
{
}

    protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
    {
        try
        {
            base.OnElementChanged(e);

            if (Control != null)
                Control.LetterSpacing = 0.12f;
        }
        catch (Exception)
        {
        }
    }
}

}
`

StackTrace of the cought exception:

10-19 20:16:07.519 20764 20764 E AndroidRuntime: android.runtime.JavaProxyThrowable: System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer from native handle 0x7fc8899774 (key_handle 0x94b6e5). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown. 10-19 20:16:07.519 20764 20764 E AndroidRuntime: --- End of inner exception stack trace --- 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00055] in <ea2bd2a1d6b340519350554a8f40cdf0>:0 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00116] in <ea2bd2a1d6b340519350554a8f40cdf0>:0 10-19 20:16:07.519 20764 20764 E AndroidRuntime: --- End of inner exception stack trace --- 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00182] in <ea2bd2a1d6b340519350554a8f40cdf0>:0 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000c1] in <ea2bd2a1d6b340519350554a8f40cdf0>:0 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <ea2bd2a1d6b340519350554a8f40cdf0>:0 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <ea2bd2a1d6b340519350554a8f40cdf0>:0 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in <ea2bd2a1d6b340519350554a8f40cdf0>:0 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at Android.Views.View.n_Invalidate (System.IntPtr jnienv, System.IntPtr native__this) [0x00000] in <ea2bd2a1d6b340519350554a8f40cdf0>:0 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.52(intptr,intptr) 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at md51558244f76c53b6aeda52c8a337f2c37.FormsTextView.n_invalidate(Native Method) 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at md51558244f76c53b6aeda52c8a337f2c37.FormsTextView.invalidate(FormsTextView.java:45) 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at android.view.ViewRootImpl$InvalidateOnAnimationRunnable.run(ViewRootImpl.java:6929) 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:933) 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at android.view.Choreographer.doCallbacks(Choreographer.java:742) 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:671) 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:919) 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:761) 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:98) 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at android.os.Looper.loop(Looper.java:156) 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6623) 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942) 10-19 20:16:07.519 20764 20764 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832 )

All these stacktrace are identical (the others are different issues not related to the first one).
https://github.com/xamarin/Xamarin.Forms/issues/2444#issue-313689253
https://github.com/xamarin/Xamarin.Forms/issues/2444#issuecomment-527560451
https://github.com/xamarin/Xamarin.Forms/issues/2444#issuecomment-541412951

For these, this occur because the renderer of the view (here the label) has been disposed before the view detachment.
The issue can be caused either by user code (the code app) or framework code, but from the stacktrace it's impossible to know what triggered that.

Can someone add this to his app (Inside the android project), the idea is to throw the exception from the dotnet side and see if we can have a more complete stacktrace through it and also give a clue to identify what label are affected in the app by providing the label text.

using System;
using Android.Content;
using Android.Runtime;
using App.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android.FastRenderers;

[assembly: ExportRenderer(typeof(Label), typeof(DebugLabelRenderer))]
namespace App.Droid
{
    public class DebugLabelRenderer : LabelRenderer
    {
        public DebugLabelRenderer(Context context)
            : base(context)
        {
        }

        [Obsolete]
        public DebugLabelRenderer(IntPtr handle, JniHandleOwnership transfer)
        {
            throw new InvalidOperationException("Access to disposed label with text : " + Text + Environment.NewLine + Environment.StackTrace);
        }
    }
}

Also see #8262

@kvpt - I've done as you asked and added the logic. After some effort, I was able to reproduce the problem, and the exception was thrown. I've cleaned some of the identifying characteristics out of the results in order to maintain app privacy.

I'm running the app on a Pixel 2 running Android 10.
Xamarin.Forms v 4.3.0.947036 (doesn't matter which v 4.x version; I tried all of them.)
Xamarin.Android.xxxx v 28.0.0.3
Prism.Unity.Forms v 7.2.0.1367

I attached a text file with the Android logcat dump, which has the pertinent details.

Let me know if you need anything else, or more details from the logcat dump.

Pixel2_Log_20191106_CustomLabelRenderer.txt

I'm seeing this as well.

Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer from native handle 0xffc6444c (key_handle 0xbece04e).

Scrolling fast through a CollectionView on Android produces the exception. My DataTemplate for the CollectionView contains 8 labels.

Xamarin.Android info:

Xamarin.Android
Version: 10.0.6.2 (Visual Studio Community)
Commit: xamarin-android/d16-3/c407838
Android SDK: /Users/joesauve/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
        4.4 (API level 19)
        5.0 (API level 21)
        5.1 (API level 22)
        6.0 (API level 23)
        7.0 (API level 24)
        7.1 (API level 25)
        8.0 (API level 26)
        8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 29.0.5
SDK Build Tools Version: 28.0.3

Build Information: 
Mono: mono/mono/2019-06@476d72b9e32
Java.Interop: xamarin/java.interop/d16-3@5836f58
LibZipSharp: grendello/LibZipSharp/d16-3@71f4a94
LibZip: nih-at/libzip/rel-1-5-1@b95cf3fd
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.27.1@8212a2d
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-3@cb41333

@jsauve Have you only labels or you also have image ?
I found in reproduction #8262, that the loading of the image add a loading delay which can cause this issue.
But perhaps just having an "heavy enough" DataTemplate can cause this issue.
What I don't understand yet is why this issue seem to only impact the fast LabelRenderer.

@kvpt, I do indeed have an image as well. Using FFImageLoading's CachedImage with a one-time binding.

When I get time later, I'll try Forms.SetFlags("UseLegacyRenderers"); and see if I can tolerate the performance hit from the the added view hierarchy complexity

@kvpt
I took a break out of my work day to try it out real quick.

I had my MainActivity.cs setup like this:

protected override void OnCreate(Bundle savedInstanceState)
{
    ...
    base.OnCreate(savedInstanceState);
    global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");
    global::Xamarin.Forms.Forms.SetFlags("UseLegacyRenderers");
    global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
    ...
    LoadApplication(new App());
}

...and I continued to experience the same exception message as before:

Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer from native handle 0xffc6444c (key_handle 0xbece04e).

However, since I'm using Forms 4.3.x, I'm not sure why SetFlags("CollectionView_Experimental") was being used. It may be legacy in the VS project template, or perhaps I erroneously added it at some point. I'm pretty sure 4.3 supports CollectionView _without_ using the CollectionView_Experimental flag. At least, as far as I recall.

So, I removed that line and wound up with this:

protected override void OnCreate(Bundle savedInstanceState)
{
    ...
    base.OnCreate(savedInstanceState);
    global::Xamarin.Forms.Forms.SetFlags("UseLegacyRenderers");
    global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
    ...
    LoadApplication(new App());
}

It seems that the CollectionView_Experimental implicitly enables fast renderers for labels (and others probably). So by removing that flag and setting the UseLegacyRenderers flag, the exception is no longer being thrown for me, and I can get on with developing this app. 馃憤
https://www.instagram.com/twinportspulse/

Was this page helpful?
0 / 5 - 0 ratings