Venkata Swamy Balaraju

Venkata Swamy Balaraju

  • NA
  • 3.9k
  • 922.3k

'Cannot access a disposed object' in Xamarin.Forms

Dec 13 2018 5:28 AM
System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Android.Widget.ListView'.
JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
JniPeerMembers+JniInstanceMethods.InvokeVirtualBooleanMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
ListView.RemoveHeaderView (Android.Views.View v)
ListViewAdapter.OnDataChanged ()
ListViewAdapter.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
TemplatedItemsList2[TView,TItem].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) TemplatedItemsList2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
TemplatedItemsList2[TView,TItem].OnItemsSourceChanged (System.Boolean fromGrouping) TemplatedItemsList2[TView,TItem].BindableOnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e)
(wrapper delegate-invoke) .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.b__49_0 ()
Thread+RunnableImplementor.Run ()
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
(wrapper dynamic-method) System.Object.25(intptr,intptr)
 
I have tried below solutions but no luck still getting an error.
  • Changed ListView CachingStrategy to RecycleElement.
  • In ListViewRenderer, overrode OnAttachedToWindow and Dispose and catch the exception.
How can I resolve this bug?
 
Thanks in advance.