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

[Bug] Layout.ResolveLayoutChanges crashing on System.ObjectDisposedException #10159

Closed
SneWs opened this issue Apr 1, 2020 · 28 comments · Fixed by #14933
Closed

[Bug] Layout.ResolveLayoutChanges crashing on System.ObjectDisposedException #10159

SneWs opened this issue Apr 1, 2020 · 28 comments · Fixed by #14933
Labels
a/fastrenderers a/label i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often m/high impact ⬛ p/Android s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. s/unverified New report that has yet to be verified t/bug 🐛
Projects

Comments

@SneWs
Copy link

SneWs commented Apr 1, 2020

Description

We are seeing sporadic crashes specifically on Android where we get System.ObjectDisposedException: Cannot access a disposed object when doing Layout.ResolveLayoutChanges for Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer

Expected Behavior

It should not crash

Actual Behavior

It crashes for customers and users

Workaround

No known workarounds currently.

Basic Information

  • Version with issue: 4.6.0-pre2

  • Last known good version: Unknown

  • IDE: VS For Mac

  • Android Support Library Version: N/A

  • Affected Devices: Random Android devices

  • Platform Target Frameworks:

    • Android: 7.0 to 10.0

Stack trace

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer'.
  at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <5c01cc23b53949bca33fa3e8371e1af3>:0
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <5c01cc23b53949bca33fa3e8371e1af3>:0
  at Android.Views.View.get_Context () [0x0000a] in <9208d5fd0c8c43b7a00f304ba0f7c041>:0
  at Xamarin.Forms.Platform.Android.Platform.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) [0x00019] in D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:1332
  at Xamarin.Forms.Forms+AndroidPlatformServices.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\Forms.cs:855
  at Xamarin.Forms.VisualElement.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00025] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:787
  at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:770
  at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:646
  at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:704
  at Xamarin.Forms.Grid.CalculateAutoCells (System.Double width, System.Double height) [0x000e5] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:133
  at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) [0x0000c] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:485
  at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x0000e] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:18
  at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
  at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
  at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:792
  at Xamarin.Forms.Layout.ResolveLayoutChanges () [0x0005c] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:392
  at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <9208d5fd0c8c43b7a00f304ba0f7c041>:0
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <9208d5fd0c8c43b7a00f304ba0f7c041>:0
  at at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.51(intptr,intptr)
@RonnyBansemer
Copy link

I can confirm the issue. Tested on Android Emulator and real device using XF 4.6.0-pre2.

[MonoDroid] System.ObjectDisposedException: Cannot access a disposed object.
[MonoDroid] Object name: 'Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer'.
[MonoDroid]   at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <26521a5118b44c858c385715922b9d5d>:0 
[MonoDroid]   at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <26521a5118b44c858c385715922b9d5d>:0 
[MonoDroid]   at Android.Views.View.get_Context () [0x0000a] in <d3b924763d4a465c85b26f6e8edc8a53>:0 
[MonoDroid]   at Xamarin.Forms.Platform.Android.Platform.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) [0x00019] in D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:1332 
[MonoDroid]   at Xamarin.Forms.Forms+AndroidPlatformServices.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\Forms.cs:855 
[MonoDroid]   at Xamarin.Forms.VisualElement.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00025] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:787 
[MonoDroid]   at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:770 
[MonoDroid]   at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:646 
[MonoDroid]   at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:704 
[MonoDroid]   at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x0007b] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:154 
[MonoDroid]   at Xamarin.Forms.TemplatedView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00019] in D:\a\1\s\Xamarin.Forms.Core\TemplatedView.cs:29 
[MonoDroid]   at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266 
[MonoDroid]   at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224 
[MonoDroid]   at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:792 
[MonoDroid]   at Xamarin.Forms.Layout.ResolveLayoutChanges () [0x0005c] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:392 
[MonoDroid]   at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <d3b924763d4a465c85b26f6e8edc8a53>:0 
[MonoDroid]   at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <d3b924763d4a465c85b26f6e8edc8a53>:0 
[MonoDroid]   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.44(intptr,intptr)

@Reveon
Copy link

Reveon commented Apr 2, 2020

tested on XF 4.6.0 pre3

    JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
    JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
    View.get_Context ()
    Platform.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:1332
    Forms+AndroidPlatformServices.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Platform.Android\Forms.cs:855
    VisualElement.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:787
    VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:770
    VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:646
    VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:704
    Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) D:\a\1\s\Xamarin.Forms.Core\Layout.cs:154
    Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:49
    Layout.UpdateChildrenLayout () D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
    Layout.OnSizeAllocated (System.Double width, System.Double height) D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
    VisualElement.SizeAllocated (System.Double width, System.Double height) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:792
    Layout.ResolveLayoutChanges () D:\a\1\s\Xamarin.Forms.Core\Layout.cs:392
    Thread+RunnableImplementor.Run ()
    IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
    (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.26(intptr,intptr)

@kingces95
Copy link
Contributor

Does anyone have a reproduction they could zip and attach?

@kingces95 kingces95 moved this from New to Needs Info in Triage Apr 4, 2020
@kingces95 kingces95 added the s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. label Apr 4, 2020
@samhouts samhouts added a/label i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often p/Android a/fastrenderers labels May 4, 2020
@samhouts samhouts moved this from Needs Info to Resource Blocked in Triage May 4, 2020
@RonnyBansemer
Copy link

RonnyBansemer commented May 6, 2020

In my example it's really hard to create a reproduction project, because the issue does not occur in a for me reproducable way. And until now I was not able to figure out what exactly triggers it. I just can say that all ui changing actions are fired on mainthread, because a race condition as described in #9753 was the first I thought of.
It seems to occur in random situations, but XF 4.6.0.726 is also affected.
Maybe @SneWs and @Reveon have more detailed information.

@Sylv1F
Copy link

Sylv1F commented May 6, 2020

Same random Error with XF 4.6.0.726
Stack Traces :

JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
View.get_Context ()
Platform.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint)
Forms+AndroidPlatformServices.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint)
VisualElement.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags)
TemplatedView.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags)
StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint)
StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders)
StackLayout.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags)
StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint)
StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders)
StackLayout.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags)
StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint)
StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders)
StackLayout.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags)
TemplatedView.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags)
StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint)
StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders)
StackLayout.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height)
Layout.UpdateChildrenLayout ()
Layout.OnSizeAllocated (System.Double width, System.Double height)
VisualElement.SizeAllocated (System.Double width, System.Double height)
Layout.ResolveLayoutChanges ()
Thread+RunnableImplementor.Run ()
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
(wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.42(intptr,intptr)

@SneWs
Copy link
Author

SneWs commented May 6, 2020

We have not been able to repro this locally, we only see this in crash reports from customers out in the wild. So unfortunately no good way of providing a solid repro project from myself.

@Reveon
Copy link

Reveon commented May 7, 2020

Just tested it on 4.6.0.726 and I still see this issue.

I tried to create repro but with no luck as the issue is very random. Maybe this could be related to #10031 (It's ImageRenderer but the stack and exception look the same).

@easoftwaresanderson
Copy link

Just tested it on 4.6.0.726 and I still see this issue.

I tried to create repro but with no luck as the issue is very random. Maybe this could be related to #10031 (It's ImageRenderer but the stack and exception look the same).

Great Reveon,

I think that it probally is the same issue , it is very random.

So, hardest to know the cause exception and could be verified asap ,

We need to find the solution quickly, this is being very bad.

@mpnow
Copy link

mpnow commented May 15, 2020

I can reliably reproduce this issue with one of our production apps.

Because it's a commercial app, I can't publicly post the source code. @kingces95 or @samhouts how can I privately submit a repro to Xamarin/Microsoft; and would you be willing/able to sign an NDA first (my boss would prefer that)?

@Sylv1F
Copy link

Sylv1F commented May 18, 2020

Hi, same problem with 4.6.0.772, i downgrade again in 4.3.0.991211

@mpnow
Copy link

mpnow commented May 18, 2020

@Sylv1F You should actually be OK with 4.4.x - I just tested every released build upwards from 4.3.x - every build up to and including 4.4.0.991864 worked fine. Starting with 4.5.0.356, this crash occurs. So it seems the bug was introduced in XF 4.5.

@Sylv1F
Copy link

Sylv1F commented May 19, 2020

@mpnow Thanks ! I upgrade framework after framework.
At this time last XF 4.4.0.991864 is Ok, and XF 4.5.0.356 work but the crash is random, so i continue upgrade slowly...
50/5000
The problem could be related to external packages ?
I use mainly Rg.Plugins.Popup, SkiaSharp, Plugin.SegmentedControl, Acr.UserDialogs

@Sylv1F
Copy link

Sylv1F commented May 22, 2020

Upgrade to XF 4.6.0.800 crash, downgrade in XF 4.5.0.266 ok

@Sylv1F
Copy link

Sylv1F commented May 26, 2020

Last really stable XF : XF 4.4.0.991864

@pedroyan
Copy link

pedroyan commented Jun 1, 2020

@Sylv1F Downgrading to XF 4.4.0.991864 "fixed" the issue for me. Thanks for sharing

@Reveon
Copy link

Reveon commented Jun 16, 2020

just tested 4.7.0.937-pre4 and the issue is still there

@Sylv1F
Copy link

Sylv1F commented Jun 23, 2020

I found the origin of my crash. I have a masterdetailpage with a MasterDetailPage.Master with a listview and a MessagingCenter.Subscribe. This Listview contains an ObservableRangeCollection .
In a detailpage I have a messagingcenter.send to modify this ObservableRangeCollection and update my ListView.

Before XF 4.5 no problem
After XF 4.5+ random crashes

I added INotifyPropertyChanged to Items, it looks better ...

@Sylv1F
Copy link

Sylv1F commented Jun 23, 2020

87/5000
Finally I deleted my bindings in my menu (listview) and the crashes disappeared

@Edgaras91
Copy link

Bug still exists in Xamarin.Forms 4.8.0.1269 for 2 emulators Android versions 7.1 and 9.0.
Crash report from AppCenter:

JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer'.

JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
View.get_Context ()
Platform.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint)
Forms+AndroidPlatformServices.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint)
VisualElement.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags)
StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint)
StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders)
StackLayout.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags)
TemplatedView.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags)
StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint)
StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders)
StackLayout.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height)
Layout.UpdateChildrenLayout ()
Layout.OnSizeAllocated (System.Double width, System.Double height)
VisualElement.SizeAllocated (System.Double width, System.Double height)
Layout.ResolveLayoutChanges ()
Thread+RunnableImplementor.Run ()
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
(wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.36(intptr,intptr)

@Edgaras91
Copy link

I can confirm, that for me XF 4.4.0.991864 did NOT fix it, still geting same exception.

@devcrux
Copy link

devcrux commented Sep 5, 2020

Bug still exist in Xamarin.Forms 4.8.0.1364

Object name: 'Xamarin.Forms.Platform.Android.FastRenderers.ImageRenderer'.
at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <42748fcc36b74733af2d9940a8f3cc8e>:0 
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <42748fcc36b74733af2d9940a8f3cc8e>:0 
at Android.Views.View.get_Context () [0x0000a] in <9a14097a65a445eaa85f6a3a1ade52a3>:0 
at Xamarin.Forms.Platform.Android.Platform.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) [0x00019] in D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:1341 
at Xamarin.Forms.Forms+AndroidPlatformServices.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\Forms.cs:921 
at Xamarin.Forms.VisualElement.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00025] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:854 
at Xamarin.Forms.Image.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Image.cs:74 
at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:837 
at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:713 
at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:771 
at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x0007b] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:154 
at Xamarin.Forms.TemplatedView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00019] in D:\a\1\s\Xamarin.Forms.Core\TemplatedView.cs:29 
at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266 
at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224 
at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:859 
at Xamarin.Forms.Layout.ResolveLayoutChanges () [0x0005c] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:392 
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <9a14097a65a445eaa85f6a3a1ade52a3>:0 
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <9a14097a65a445eaa85f6a3a1ade52a3>:0 
t (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr)

@devcrux
Copy link

devcrux commented Sep 9, 2020

Bug still exist in Xamarin.Forms 4.8.0.1364

Object name: 'Xamarin.Forms.Platform.Android.FastRenderers.ImageRenderer'.
at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <42748fcc36b74733af2d9940a8f3cc8e>:0 
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <42748fcc36b74733af2d9940a8f3cc8e>:0 
at Android.Views.View.get_Context () [0x0000a] in <9a14097a65a445eaa85f6a3a1ade52a3>:0 
at Xamarin.Forms.Platform.Android.Platform.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) [0x00019] in D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:1341 
at Xamarin.Forms.Forms+AndroidPlatformServices.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\Forms.cs:921 
at Xamarin.Forms.VisualElement.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00025] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:854 
at Xamarin.Forms.Image.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Image.cs:74 
at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:837 
at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:713 
at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:771 
at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x0007b] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:154 
at Xamarin.Forms.TemplatedView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00019] in D:\a\1\s\Xamarin.Forms.Core\TemplatedView.cs:29 
at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266 
at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224 
at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:859 
at Xamarin.Forms.Layout.ResolveLayoutChanges () [0x0005c] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:392 
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <9a14097a65a445eaa85f6a3a1ade52a3>:0 
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <9a14097a65a445eaa85f6a3a1ade52a3>:0 
t (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr)

See what I found where the crash is happening: https://github.com/xamarin/Xamarin.Forms/blob/main/Xamarin.Forms.Platform.Android/Platform.cs
Line 1332

// FIXME: potential crash
IVisualElementRenderer visualElementRenderer = GetRenderer(view);

@PureWeen
Copy link
Contributor

Can anyone who is seeing this issue test with the nuget here?

https://dev.azure.com/xamarin/public/_build/results?buildId=25860&view=artifacts&type=publishedArtifacts

And then please let me know if you still see the exception?

@TsplayerT
Copy link

I tested a project with the same error, Xamarin 5.0.0.1539-pre2 and it still persists

System.ObjectDisposedException: Cannot access a dropped object

Using this line Forms.SetFlags ("UseLegacyRenderers") in the project the exception have the ObjectName:
Xamarin.Forms.Platform.Android.AppCompat.FrameRenderer

Without flag line the ObjectName:
Xamarin.Forms.Platform.Android.FastRenderers.FrameRenderer

@mpnow
Copy link

mpnow commented Jan 4, 2021

I'm wondering if anyone has tried this with Xamarin 5.0 pre-6, and what their results have been?

I haven't been able to repro the crash with that version, but then again, it's an intermittent crash so it's hard for us to reproduce.

@AbhijeetChowdhury92
Copy link

AbhijeetChowdhury92 commented Feb 21, 2021

I am getting the same crash with Xamarin.Forms 5.0.0.1874 and it's occurring in Android version > 10

JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) View.get_LayoutParameters () ButtonLayoutManager.UpdateTextAndImage () ButtonLayoutManager.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs) BindableObject.OnPropertyChanged (System.String propertyName) Element.OnPropertyChanged (System.String propertyName) BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) BindingExpression.Apply (System.Boolean fromTarget) BindingExpression+BindingExpressionPart.<PropertyChanged>b__49_0 () BindingExpression+BindingExpressionPart.PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) BindingExpression+WeakPropertyChangedProxy.OnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs) LocalizationResourceManager.Invalidate () LocalizationResourceManager.SetCulture (System.Globalization.CultureInfo language) SettingsPageViewModel.<ChangeLanguage>b__31_1 (System.String selectedLanguageName) AnonymousSafeObserver1[T].OnNext (T value)
Sink1[TTarget].ForwardOnNext (TTarget value) ObserveOnObserverNew1[T].DrainStep (System.Collections.Concurrent.ConcurrentQueue1[T] q) ObserveOnObserverNew1[T].DrainShortRunning (System.Reactive.Concurrency.IScheduler recursiveScheduler)
<.cctor>b__17_0 (System.Reactive.Concurrency.IScheduler scheduler, System.Reactive.ObserveOnObserverNew1[T] self) HandlerScheduler+<>c__DisplayClass9_01[TState].b__0 ()
Thread+RunnableImplementor.Run ()
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
(wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.46(intptr,intptr)`

@VNGames
Copy link

VNGames commented Feb 23, 2021

Xamarin.Forms.Platform.Android/Platform.cs
has a fix for this

IVisualElementRenderer visualElementRenderer = GetRenderer(view);

if (visualElementRenderer == null || visualElementRenderer.View.IsDisposed())
{
return new SizeRequest(Size.Zero, Size.Zero);
}

var context = visualElementRenderer.View.Context;

It should just be updated here
Xamarin.Forms.Platform.Android/AppCompat/Platform.cs

// FIXME: potential crash
IVisualElementRenderer visualElementRenderer = Android.Platform.GetRenderer(view);

var context = visualElementRenderer.View.Context;

@jfversluis
Copy link
Member

@VNGames It wouldn't have hurted to add the code there as well, although it is strongly encouraged to use the "fast" renderers which should be enabled by default.

However, for whoever that might still be watching this, a PR (#14933) for this is open now, would you be able to grab the NuGet as described here and let us know if this fixes this issue? That will greatly speed up the review process.

Besides verifying if this particular issue is fixed also be sure to check other scenarios in the same area to make sure that this fix doesn't accidentally has side-effects 🙂

Thanks!

Triage automation moved this from Resource Blocked to Closed Dec 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/fastrenderers a/label i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often m/high impact ⬛ p/Android s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. s/unverified New report that has yet to be verified t/bug 🐛
Projects
Triage
  
Closed
Development

Successfully merging a pull request may close this issue.