Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Xamarin.Forms bug? System.ObjectDisposedException: Cannot access a disposed object



  • AhmedElashkerAhmedElashker USMember ✭✭

    This was happening with me in a tableview when I was popping the view from the navigation stack.

    Apparently the reason is a function that refreshes table sections (add/remove) was being called at the time of view disappearing. A small 'if' check solved my problem.

  • hi @Devology i am facing same issue.but i dont have listview in my page.i have PullToRefreshLayout.then how can i solve this error with CachingStrategy="RecycleElement" ?

  • @FishaTariku.2649 said:
    Hi i am having a nearly similar problem:

    System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Xamarin.Forms.Platform.Android.ScrollViewRenderer'.

    The error occurred when i pop a page from a navigation stack like this await Navigation.PopAsync(). and the page i tries to pop has a ScrollView.

    Can anyone help in this regards!

    Did you solve this issue?

  • FishaTarikuFishaTariku USMember
    edited December 2017

    I have got a temporary solution. Just adding one line of code before popping the page.

    await Task.Delay(10); //Solution

    await Navigation.PopAsync()

  • TamasMatraiTamasMatrai HUUniversity ✭✭
    edited January 2018

    I have a similar issue (XF

    FontAwareButtonRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs`1[TElement] e)
    System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Android.Graphics.Bitmap'.

    Cannot access a disposed object. Object name: 'Android.Graphics.Bitmap'.

    JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
    JniPeerMembers+JniInstanceMethods.InvokeAbstractVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
    Bitmap.Recycle ()
    ButtonDrawable.Reset ()
    ButtonRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs1[TElement] e) 6 FontAwareButtonRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs1[TElement] e)
    VisualElementRenderer`1[TElement].SetElement (TElement element)

  • TinNguyen95TinNguyen95 CHMember ✭✭

    Does someone have a good explanation why setting CachingStrategy to RecycleElement magically fixes the ObjectDisposedException: Cannot access a disposed object?

  • JohnHardmanJohnHardman GBUniversity admin

    @RubnFernndezSouto @FishaTariku @FishaTariku.2649

    What you were/are seeing may be this XF bug:
    I hit this if a page is scrolling on Android when PopAsync is called

  • MosCDMosCD Member ✭✭

    @Devology said:
    I've just tweaked one of my projects to explicitly set the CachingStrategy on the ListView to RecycleElement and it's not been seen since. However I believe it can have knock-on effects with Converters, but so far in my case it seems to be okay. It's too early to say conclusively whether it's fixed the issue (GestureRecognizer related ObjectDisposed), but I thought I'd offer the update just in case it helps anyone else out.

    Note the auto-complete in the XAML doesn't show up, so you'll have to add

    <ListView CachingStrategy = "RecycleElement" ...>

    This is actually the opposite of what @AdamP suggested...

    If you have your ListViewCachingStrategy set to RecycleElement, try disabling that and see if that stops the issue.

    I never explicitly set a CachingStrategy, the default is RetainElement and given that sometimes the stack trace shows RetainElement, then I thought swapping to RecycleElement might actually help.

    Fingers crossed.

    this solved my issue

  • Srinivas_SSrinivas_S INMember ✭✭

    Hi all, I am facing a similar problem,

    Cannot access a disposed object.Object name: 'Xamarin.Forms.Platform.Android.Platform+DefaultRenderer'.

    Here is the stack trace.

    Cannot access a disposed object.Object name: 'Xamarin.Forms.Platform.Android.Platform+DefaultRenderer'. StackTrace: at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <3cb12bce834a498199b2be6cd3e00922>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualInt32Method (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <3cb12bce834a498199b2be6cd3e00922>:0 at Android.Views.View.get_Visibility () [0x0000a] in <ff199c98c3f84852925dd37a0ef6113a>:0 at Xamarin.Forms.Platform.Android.VisualElementTracker.UpdateIsVisible () [0x0001d] in <fb1b373bb41f422cab210b1850374a59>:0 at Xamarin.Forms.Platform.Android.VisualElementTracker.HandlePropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x002dc] in <fb1b373bb41f422cab210b1850374a59>:0 at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs) at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00012] in <42fe931976e64c199eddde45068a6c09>:0 at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in <42fe931976e64c199eddde45068a6c09>: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 <42fe931976e64c199eddde45068a6c09>: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 <42fe931976e64c199eddde45068a6c09>:0 at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x001f9] in <42fe931976e64c199eddde45068a6c09>:0 at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in <42fe931976e64c199eddde45068a6c09>:0 at Xamarin.Forms.BindingExpression+BindingExpressionPart.<PropertyChanged>b__47_0 () [0x00000] in <42fe931976e64c199eddde45068a6c09>:0 at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <ff199c98c3f84852925dd37a0ef6113a>:0 at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <ff199c98c3f84852925dd37a0ef6113a>:0 at (wrapper dynamic-method) System.Object.edea8c80-2e5f-41b3-9652-6f9bebf7fd8c(intptr,intptr) Method: ; AssertSelf

    I have added <ListViewCachingStrategy>RecycleElement</ListViewCachingStrategy> to ListView but still issue remains same. Can any one suggest me to solve this.


  • BhaurajBiradar.9064BhaurajBiradar.9064 USMember ✭✭✭
    edited June 2018


    Foe listview CachingStrategy add below code


  • Srinivas_SSrinivas_S INMember ✭✭

    Hi @BhaurajBiradar.9064 ,

    I have tried this but not worked for me. When I use my app 2 to 3 hours continuously, app getting crashed. May I know, is there any particular XF version to use this code snippet


    Thanks for your suggestion

  • Try to clear ScrollView by overriding OnDisappearing method.
    Mine works by clearing the children in my StackLayout before base.OnDisappearing().

  • BhaurajBiradar.9064BhaurajBiradar.9064 USMember ✭✭✭

    Hi @Srinivas_S

    Please see this youtube video, this will help you..

  • amirvenusamirvenus USMember ✭✭✭
    edited April 2019

    I am also getting the same crash report on AppCentre

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

    JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
    JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
    DrawerLayout.RemoveDrawerListener (Android.Support.V4.Widget.DrawerLayout+IDrawerListener listener)
    NavigationPageRenderer.Dispose (System.Boolean disposing)
    Object.Dispose ()
    FragmentContainer.OnDestroyView ()
    Fragment.n_OnDestroyView (System.IntPtr jnienv, System.IntPtr native__this)
    (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.47(intptr,intptr)

  • crigintcrigint Member ✭✭

    I had the same problem with a ScrollView:

    System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Xamarin.Forms.Platform.Android.ScrollViewRenderer'.

    I solved putting the ScrollView inside a StackLayout.

Sign In or Register to comment.