Bug 53344 - Android+Forms: Cannot access a disposed object because page closed, or Content of page set to new content => error in layout + binding
Summary: Android+Forms: Cannot access a disposed object because page closed, or Conten...
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: unspecified
Hardware: PC Windows
: --- critical
Target Milestone: ---
Assignee: Paul DiPietro [MSFT]
Depends on:
Reported: 2017-03-15 09:26 UTC by t.antlinger@controllerbox.eu
Modified: 2017-06-20 17:52 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

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

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

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

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

Related Links:

Description t.antlinger@controllerbox.eu 2017-03-15 09:26:38 UTC
# Steps to reproduce
Just rebuild GUI in a Page very often (Set Content with new Layout and View within)
Just update Properties via Binding and Close the Page

Here are realy MANY ways to make Xamarin-Forms crash, and no Code in the Stacktrace is from OUR Application.
It helps to set the whole content invisible bevore remove the Content from the Page or before closing the page, but that is not always possible and should not be neccesarry.

# Expected behavior
No Crash at all. If the Component is disposed because it is removed, no Layout should happen, no Properties should be changed via Binding.
If you not can make it stop crashing => OnCrash check if component would be visible from Xamarin.Forms or is even attatched to something and pretend nothing happend.

# Actual behavior
Random Crashes, when closing pages, or setting new content to a page because the old components still try to layout themselfes or even try to update bound properties. Using Xamarin.Forms feels like is spend most time on progromming doing workarounds.

# Supplemental info (logs, images, videos)

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Xamarin.Forms.Platform.Android.ImageRenderer'.
  at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00030] in <6924eb51f5c447ff8cadc8e6c81ab6b3>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualInt32Method (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00001] in <6924eb51f5c447ff8cadc8e6c81ab6b3>:0 
  at Android.Views.View.get_Visibility () [0x0000a] in <5c657737816b4742b9656e6ae00c39d6>:0 
  at Xamarin.Forms.Platform.Android.VisualElementTracker.UpdateIsVisible () [0x0001d] in <00979a7978ab4144a58919b163f63751>:0 
  at Xamarin.Forms.Platform.Android.VisualElementTracker.HandlePropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x002dc] in <00979a7978ab4144a58919b163f63751>:0 
  at (wrapper delegate-invoke) <Module>:invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
  at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00012] in <acdeeafc83bc4812bab1da9f3ce77dea>:0 
  at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in <acdeeafc83bc4812bab1da9f3ce77dea>:0 
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.BindableObject+SetValueFlags attributes, System.Boolean silent) [0x000fb] in <acdeeafc83bc4812bab1da9f3ce77dea>:0 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.BindableObject+SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0014b] in <acdeeafc83bc4812bab1da9f3ce77dea>:0 
  at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x001f9] in <acdeeafc83bc4812bab1da9f3ce77dea>:0 
  at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in <acdeeafc83bc4812bab1da9f3ce77dea>:0 
  at Xamarin.Forms.BindingExpression+BindingExpressionPart.<PropertyChanged>b__47_0 () [0x00000] in <acdeeafc83bc4812bab1da9f3ce77dea>:0 
  at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in <5c657737816b4742b9656e6ae00c39d6>:0 
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <5c657737816b4742b9656e6ae00c39d6>:0 
  at (wrapper dynamic-method) System.Object:9849c003-e8ff-44ee-8910-2fb09137fe3e (intptr,intptr)

# Test environment (full version information)
Xamarin.Android 7.1.0-43
amarin for Visual Studio 4.3
Xamarin.Forms v.
Comment 1 Paul DiPietro [MSFT] 2017-03-20 13:31:41 UTC
Please upload a reproduction so we can avoid doing any guesswork as to the exact code you're using to produce the issue. Thanks.
Comment 2 Paul DiPietro [MSFT] 2017-06-20 17:52:28 UTC
Because we have not received a reply to our request for more information we are closing this issue. If you are still encountering this issue, please reopen the ticket and attach a project that demonstrates the issue if you're still experiencing it as of the latest prerelease or nightly build.