Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Unable to activate instance of type Xamarin.Forms.Platform.Android.Platform+DefaultRenderer #12867

Open
rubiomiguel06 opened this issue Nov 16, 2020 · 15 comments
Labels
a/DragAndDrop p/Android s/unverified New report that has yet to be verified t/bug 🐛
Milestone

Comments

@rubiomiguel06
Copy link

rubiomiguel06 commented Nov 16, 2020

Description

I created a custom control called DragAndSwapContainer which implements two custom behaviors: DragBehavior and DropBehavior.

DragBehavior basically adds a PanGestureRecognizer to the View and emits an event when the View is being 'dragged' (and also translates the view according to the Pan done by the user). On the other side, DropBehavior listens to this events and emits other events when a View is passing over the container or when a View is dropped inside.

DragAndSwapContainer acts as a container that can receive other views, and as a draggable and droppable view at the same time. The goal of this container is to enable the user to swap between two views by dragging and dropping one into the other one.

When a View is dropped inside this Container what I do is, basically, to swap the Children Views that both containers have (the one with the view that was dragged, and the one receiving the dropped view). Here's a piece of code for the DragAndSwapContainer (which inherits from Grid):

private void OnViewDroppedInside(object sender, DroppedEventArgs e)
{
    var draggedViewContainer = e.DroppedView.Parent as DragAndSwapContainer;

    draggedViewContainer.Children.Add(this.Children.First());
    this.Children.Add(e.DroppedView);
}

Since each View can have only one parent, this works fine: Child View is exchanged by the DragAndSwapContainers.

Everything works fine as respects to iOS and Windows, but I am facing some problems with Android.

I am getting the following error #8888 when swapping two views. After some debugging I conclude that the problem arises because while swapping the children Android native renderers are disposed, so I lose track of the View.

Also it is something that doesn't happen always, seems that there's some timings issues. If I attach my Analytics service (which reports to a cloud server and adds some overhead) the issue happens way more often.

The error mentioned seems to be fixed in the Xamarin.Forms version I have (since it was merged already in v4.4.0) but I'm still having the exact same error call stacks.

I managed to recreate this problem in a separate project (see attached) but only if using UXCam Analytics.. Unfortunately I couldn't reproduce it (at least in a fast reproducible way) without the use of UXCam, and I'm unable to share the AppKey I use to start a UXCam session through here.

Here's the error I get when the app crashes:

android.runtime.JavaProxyThrowable
System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.Platform+DefaultRenderer from native handle 0x78115f90c4 (key_handle 0x87c6c2d). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.Platform+DefaultRenderer::.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) [0x000b5] in <2df86f44c8e946618f31cb3aed952f5b>:0 at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in <2df86f44c8e946618f31cb3aed952f5b>:0 --- End of inner exception stack trace --- at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x0017e] in <2df86f44c8e946618f31cb3aed952f5b>:0 at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x00023] in <2df86f44c8e946618f31cb3aed952f5b>:0 at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <2df86f44c8e946618f31cb3aed952f5b>:0 at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <2df86f44c8e946618f31cb3aed952f5b>:0 at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in <2df86f44c8e946618f31cb3aed952f5b>:0 at Android.Views.View.n_SetOnTouchListener_Landroid_view_View_OnTouchListener (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_l) [0x00000] in <2df86f44c8e946618f31cb3aed952f5b>:0 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.37(intptr,intptr,intptr)

Steps to Reproduce

  1. Run the sample project on Android (with a UXCam AppKey inserted at UXCamAnalytics.cs)
  2. Start dragging and dropping views
  3. Eventually App crashes

Expected Behavior

App shouldn't crash and should work as it does on UWP and iOS

Basic Information

  • Version with issue: XF 4.8.0.1451
  • Last known good version: -
  • IDE: Visual Studio for Windows (v16.8.1)
  • Platform Target Frameworks:
    • Android: 9.0 (Pie)
  • Nuget Packages: UXCam v3.2.1
  • Affected Devices: Tested on Samsung devices (Galaxy A21s, Galaxy Tab S4, Galaxy S8)

Reproduction Link

DragAndDrop.zip

Screenshots

image

@rubiomiguel06 rubiomiguel06 added s/unverified New report that has yet to be verified t/bug 🐛 labels Nov 16, 2020
@samhouts samhouts added this to New in Triage Nov 16, 2020
@PureWeen PureWeen added this to the 5.0.0 milestone Dec 7, 2020
@PureWeen PureWeen added this to To do in vNext+1 (5.0.0) via automation Dec 7, 2020
@PureWeen
Copy link
Contributor

@rubiomiguel06 I've been moving these cats around for awhile now and I'm not getting any crashes

I'm testing on an S9 and not seeing anything. Do you see this issue on any simulator versions? Can you try the latest 5.0 prerelease to see if you are having issues there?

@PureWeen PureWeen moved this from New to Needs Info in Triage Dec 10, 2020
@PureWeen PureWeen added the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Dec 10, 2020
@rubiomiguel06
Copy link
Author

@PureWeen thanks for trying to get the error. Unfortunately I'm just starting my vacation days, so until I come back I won't be able to test with the latest 5.0 prerelease. But please, don't close this issue for inactivity. This will be the first thing I'll focus on as soon as I am back.
Anyway, did you try it using UXCam? I'll also try to make a sample where the use of UXCam is not needed, since it makes it difficult to test.

@Redth Redth added this to To do in v5.0.1 via automation Dec 18, 2020
@Redth Redth removed this from To do in vNext+1 (5.0.0) Dec 18, 2020
@rubiomiguel06
Copy link
Author

rubiomiguel06 commented Jan 11, 2021

Hi @PureWeen, I've tested the latest 5.0 release and the problem persists.

One thing I've just found out is that the exception occurs only for Android 10 devices (or at least I wasn't able to reproduce it on other Android versions, excepting Android 11 which I could not test yet because I don't have a device or simulator with this version).

Please try the example I attach below where I added a UXCam key and updated the Xamarin.Forms version to the latest available one (v5.0.0.1874). Running it on Debug mode on an Android 10 device or simulator (connected to internet, so UXCam works), after some drags and drops, the exception should arise.

I've tested on the Android simulator Pixel 2 Q 10.0 - API 29 with the expected results (exception occurring after moving containers around).

DragAndDrop.zip

@Redth Redth removed the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Jan 21, 2021
@PureWeen PureWeen moved this from Needs Info to New in Triage Jan 22, 2021
@jsuarezruiz
Copy link
Contributor

jsuarezruiz commented Feb 8, 2021

Thanks for the attached repro sample!.
I have not managed to get the crash dragging several times in Android simulator Pixel 2 Q 10.0 - API 29.
@PureWeen Could you try the attached repro sample?

@jsuarezruiz jsuarezruiz moved this from New to Needs Info in Triage Feb 8, 2021
@jsuarezruiz jsuarezruiz added the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Feb 8, 2021
@rubiomiguel06
Copy link
Author

@jsuarezruiz thanks for trying to reproduce it on your side!
One question, did you run the sample on Debug mode and with an internet connection?
I ask you because I didn't get any new sessions on the UXCam analytics dashboard.

@Redth Redth removed the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Mar 4, 2021
@PureWeen PureWeen moved this from Needs Info to New in Triage Mar 5, 2021
@rmarinho
Copy link
Member

rmarinho commented Mar 8, 2021

Hi @rubiomiguel06 i tried to reproduce and frag and drop the cards a lot of times and i wasn't able to make it crash. Anything special ? tested Pixel 2 simulator API 29

@rmarinho rmarinho added the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Mar 8, 2021
@rmarinho rmarinho moved this from New to Needs Info in Triage Mar 8, 2021
@rubiomiguel06
Copy link
Author

rubiomiguel06 commented Mar 9, 2021

Hi @rmarinho, thanks for giving it a try. I ask you the same I did to @jsuarezruiz : did you run the sample on Debug mode and with an internet connection? I haven't seen any activity log on the UXCam analytics.
I attach a video showing the crash I get.

The steps are:

  1. Run the sample (this) on Debug Mode.
  2. Check there's a working internet connection on the device.
  3. Drag and Drop cards. It might be that doing it fast makes it crash more often.
DragAndDrop_Exception.mp4

@rachelkang
Copy link
Contributor

Hi, @rubiomiguel06 - thanks for elaborating. Confirming that I'm able to reproduce this on XF 5.0 on visual studio. Interestingly (although perhaps irrelevant), I was unable to reproduce the issue on VSMac. As you mentioned, I do think this may be a performance issue related to the speed and # of times in which the drag-and-drop is performed

@rachelkang rachelkang removed the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Mar 18, 2021
@rachelkang rachelkang moved this from Needs Info to Ready For Work in Triage Mar 18, 2021
@Redth Redth moved this from Ready For Work to Needs Estimate in Triage Mar 22, 2021
@Anup-UXCam
Copy link

Anup-UXCam commented May 23, 2022

Hi, we've had a customer come to us with this particular issue. The stack traces are pointing to the setting of the onTouchListener. Any updates on this? Thanks!

@MitchBomcanhao
Copy link

I'm now running into a similar issue too

@rubiomiguel06
Copy link
Author

This ended up being an issue related directly with UXCam Android. They have fixed it and the issue is gone. I will close it

Triage automation moved this from Needs Estimate to Closed Feb 15, 2023
v5.0.1 automation moved this from To do to Done Feb 15, 2023
@MitchBomcanhao
Copy link

I'm still getting a similar issue on a page that contains a Listview, and some users one some devices seem to be able to trigger the issue repeatedly, but I've not been able to do it on any device I've tried so far. The google play store automated test does trigger this failure on one of their test devices (but not always), and viewing the video and trying to reproduce their interaction yelded no results :( there's no drag and drop, no fancy behaviours, just a list that can be tapped on to call a command.

@Anup-UXCam
Copy link

Anup-UXCam commented Feb 16, 2023

This is not an issue related with UXCam Android, the SDK is just adding a onTouchListener to views and it throws this exception. To avoid crashing apps we have disabled one of our features on the latest version of our Xamarin SDK. This is still a Xamarin issue, the views should not be throwing this exception on a simple onTouchListener.

@rubiomiguel06 rubiomiguel06 reopened this Feb 16, 2023
Triage automation moved this from Closed to New Feb 16, 2023
v5.0.1 automation moved this from Done to In progress Feb 16, 2023
@MitchBomcanhao
Copy link

MitchBomcanhao commented Feb 23, 2023

I think I may have reproduced the app hanging/crashing on my own device (very little details on what is actually going on). The trick was going onto the accessibility settings on my android 11 device toggling "Remove animations" to ON.
Then, when I'm triggering an action which will dismiss my current page (built with rg plugin popup) the app stops working with the dreaded "unable to activate instance" error.
So, disabling animations makes things go bang...

@MitchBomcanhao
Copy link

ok, a bit more information - it seems that the popup page goes bang when animations are disabled and you replace the contents of the page, eg setting this.Content to a blank grid (or whatever you may want, we had an activity indicator) made it explode. this then bubbles up to the default renderer constructor failure that ultimately takes down the application.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/DragAndDrop p/Android s/unverified New report that has yet to be verified t/bug 🐛
Projects
Triage
  
New
v5.0.1
In progress
Development

No branches or pull requests

8 participants