Bug 57423 - System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Xamarin.Forms.Platform.Android.FormsImageView'
Summary: System.ObjectDisposedException: Cannot access a disposed object. Object name:...
Status: ASSIGNED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Paul DiPietro [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-06-13 06:07 UTC by Britton Beckham
Modified: 2018-04-16 14:01 UTC (History)
4 users (show)

Tags:
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 for Bug 57423 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
ASSIGNED

Description Britton Beckham 2017-06-13 06:07:02 UTC
FROM MOBILE CENTER CRASH REPORT:

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

CANNOT ACCESS A DISPOSED OBJECT. OBJECT NAME: 'XAMARIN.FORMS.PLATFORM.ANDROID.FORMSIMAGEVIEW'.
1 JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
2 JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
3 ImageView.SetImageResource (System.Int32 resId)
4 ImageRenderer+<UpdateBitmap>d__9.MoveNext ()
5 ExceptionDispatchInfo.Throw ()
6 AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state)
7 SyncContext+<>c__DisplayClass2_0.<Post>b__0 ()
8 Thread+RunnableImplementor.Run ()
9 IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
10 (wrapper dynamic-method) System.Object:0a8093a0-3fe9-4023-8315-e4300e756a71 (intptr,intptr)

I have an application that is nesting instances of a page several deep. For example, say you are view a container page. A container can have sub-containers. So you can move indefinitely down the number of nested containers. You can also delete a container at any point along the way. Anytime a container is modified or deleted, it fires off a MessagingCenter event that forces the Container page to rebuild the BindingContext. This error happens after I perform a delete operation after having browsed down and then backing up a level or two:

private async void Delete_OnClicked(object sender, EventArgs e)
{
	var confirm = await DisplayAlert("Delete Container?", "All items in this container will automactially be saved and moved to the parent location. Are you sure you want to delete this container?", "Delete", "Cancel");
	if (confirm)
	{
		UserDialogs.Instance.ShowLoading("Deleting container");

		var model = BindingContext as ItemListViewModel;

		try
		{
			await App.Data.DeleteContainer(model.IdRef);
			await Navigation.PopAsync();
		}
		catch (AppValidationException ex)
		{
			await DisplayAlert("Ooops", ex.Message, "OK");
		}
		finally
		{
			UserDialogs.Instance.HideLoading();
		}
	}
}

You can see the only thing I am doing here is deleting the container from local data and then popping the page. But this Android image error gets tripped. This happens when I navigate in a couple deep, backout and then delete. I believe one of pages out of the nav stack that is still active in memory is receives a refresh command from a container being deleted and then somehow the image handle is invalid... GC issue? I'm not sure.
Comment 1 Paul DiPietro [MSFT] 2017-06-13 23:42:07 UTC
Could you upload a complete but minimized reproduction that demonstrates the issue? You can set the status back to new upon doing so. This will help with investigation so we know exactly what your app is attempting to do. I would also suggest testing against the latest 2.3.5-pre or the nightly feed to see if the issue has not been resolved, if you haven't already done so. Thanks in advance.
Comment 2 Britton Beckham 2017-06-15 02:35:21 UTC
I will test it against the latest before I move to reproduce in smaller project. Thanks
Comment 3 Devender 2018-02-26 11:33:41 UTC
Hi, Is there any fix done for this issue or any update ?
My production Android app is getting crashed randomly with similar bug report(From App Center)

Xamarin Exception Stack:
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Xamarin.Forms.Platform.Android.FormsImageView'.
  at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <fe08304d8cd640efbf7416535afef3fa>:0
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <fe08304d8cd640efbf7416535afef3fa>:0
  at Android.Views.View.Measure (System.Int32 widthMeasureSpec, System.Int32 heightMeasureSpec) [0x00035] in <e3636f6dacc64cc7b3095818aa0dc123>:0
  at Xamarin.Forms.Platform.Android.ViewRenderer`2[TView,TNativeView].GetDesiredSize (System.Int32 widthConstraint, System.Int32 heightConstraint) [0x0002d] in <aae4e9ce5a5b4d3eaec4edf21079f3fa>:0
  at Xamarin.Forms.Platform.Android.AppCompat.Platform.Xamarin.Forms.Internals.IPlatform.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) [0x0008d] in <aae4e9ce5a5b4d3eaec4edf21079f3fa>:0
  at Xamarin.Forms.VisualElement.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00033] in <1aabc0fecdaa41b6a5c04760c77bb648>:0
  at Xamarin.Forms.Image.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in <1aabc0fecdaa41b6a5c04760c77bb648>:0
  at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in <1aabc0fecdaa41b6a5c04760c77bb648>:0
  at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in <1aabc0fecdaa41b6a5c04760c77bb648>:0
  at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00052] in <1aabc0fecdaa41b6a5c04760c77bb648>:0
  at Xamarin.Forms.StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint) [0x00236] in <1aabc0fecdaa41b6a5c04760c77bb648>:0
  at Xamarin.Forms.StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders) [0x00058] in <1aabc0fecdaa41b6a5c04760c77bb648>:0
  at Xamarin.Forms.StackLayout.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x0005b] in <1aabc0fecdaa41b6a5c04760c77bb648>:0
  at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x0014b] in <1aabc0fecdaa41b6a5c04760c77bb648>:0
  at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in <1aabc0fecdaa41b6a5c04760c77bb648>:0
  at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in <1aabc0fecdaa41b6a5c04760c77bb648>:0
  at Xamarin.Forms.Layout+<>c.<OnChildMeasureInvalidated>b__40_0 () [0x00080] in <1aabc0fecdaa41b6a5c04760c77bb648>:0
  at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <e3636f6dacc64cc7b3095818aa0dc123>:0
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <e3636f6dacc64cc7b3095818aa0dc123>:0
  at (wrapper dynamic-method) System.Object:d26a6635-e316-4fb9-85d1-dd049a6e1a44 (intptr,intptr)
Comment 4 svsankari90 2018-04-16 14:01:42 UTC
Any update on this issue? When will this be fixed? Android app with Xamarin Forms is crashing with ObjectDisposedException randomly - Xamarin version used is 4.8.0.760 (fc93f3f5b)