-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Unable to activate instance of type LabelRenderer from native handle #2444
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:
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 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:
|
@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 Run the solution |
I found a work around:
} |
The workout provide by @MereDoku worked for me. For quick reference, here is the label renderer. `[assembly:ExportRenderer(typeof(CustomLabel), typeof(CustomLabelRenderer))]
}` |
@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? |
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.
|
@jordan-surveycom My changes are included in 4.2 release. 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 #7163 (comment), 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. I have no Label custom renderers.
|
Same here on Xamarin.Forms 4.2.0.848062 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.
} StackTrace of the cought exception:
|
All these stacktrace are identical (the others are different issues not related to the first one). For these, this occur because the renderer of the view (here the label) has been disposed before the view detachment. 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. 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. |
I'm seeing this as well.
Scrolling fast through a CollectionView on Android produces the exception. My DataTemplate for the CollectionView contains 8 labels. Xamarin.Android info:
|
@jsauve Have you only labels or you also have image ? |
@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 |
@kvpt I had my MainActivity.cs setup like this:
...and I continued to experience the same exception message as before:
However, since I'm using Forms 4.3.x, I'm not sure why So, I removed that line and wound up with this:
It seems that the |
Bug from Bugzilla 57802 https://bugzilla.xamarin.com/show_bug.cgi?id=57802
Description
The following exception is sometimes thrown:
It seems to revolve around a missing constructor
LabelRenderer(IntPtr javaReference, JniHandleOwnership transfer)
. That constructor does exist on the base classFormsTextView
, 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
Reproduction Link
Someone else suggested this https://bugzilla.xamarin.com/attachment.cgi?id=23223
The text was updated successfully, but these errors were encountered: