Hi
My Android xamarin.forms application uses a Navigation stack to display various views, I often has a list on a screen (a) That once a cell was clicked I push onto the stack a new screen (B), the user completes some form fields and then clicks a button to save. Once They click the ' Save ' button a task is created on the thread pool to asynchronously perform some work (no async/await And no dependency on any UI) and the view are popped back to screen (A).
Once the task is completed, it fires a simple event using the PubSub library, the UI thread, so screens (a) has the Oppo Rtunity to refresh from the local database and it does.
The problem is if I go to drag the updated list in screen (A) and the app crashes with an objectdisposedexceptionI Ntermittently (like 1 in ...)
System.ObjectDisposedException: CannotAccess a disposedObject.ObjectName: ' Android.Views.GestureDetector '.AtJava.Interop.Jnipeermembers.Assertself (Java.Interop.Ijavapeerable Self) [0x00030] Inch /Users/Builder/Data/Lanes/3819/c1d1c79c/Source/Java.Interop/Src/Java.Interop/Java.Interop/Jnipeermembers.Cs:153AtJava.Interop.Jnipeermembers+Jniinstancemethods.Invokevirtualbooleanmethod (System.StringEncodedmember, Java.Interop.Ijavapeerable Self, Java.Interop.Jniargumentvalue*Parameters) [0x00002] Inch /Users/Builder/Data/Lanes/3819/c1d1c79c/Source/Java.Interop/Src/Java.Interop/Java.Interop/Jnipeermembers.Jniinstancemethods_invoke.Cs:57AtAndroid.Views.Gesturedetector.Ontouchevent (Android.Views.MotioneventEv) [0x0002c] Inch /Users/Builder/Data/Lanes/3819/c1d1c79c/Source/Monodroid/Src/Mono.Android/Platforms/Android-23/Src/Generated/Android.Views.Gesturedetector.Cs:1546Atxamarin. Forms. Platform. Android. Visualelementrenderer ' 1[telement]. Android.Views.View.IOnTouchListener.OnTouch (Android.Views.View V, Android.Views.MotionEvent e) [0x0003f] in C \ Buildagent2\work\aad494dc9bc9783\xamarin.forms.platform.android\visualelementrenderer.cs:101 at Android.views.view+iontouchlistenerinvoker.n_ontouch_landroid_view_view_landroid_view_motionevent_ ( System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v, System.IntPtr native_e) [0x00019] in/users/ builder/data/lanes/3819/c1d1c79c/source/monodroid/src/mono.android/platforms/android-23/src/generated/ android.views.view.cs:3558 at (wrapper Dynamic-method) System.object:4eaabbb9-8c1c-4ea1-b505-44c325bbb1ab (IntPtr , intptr,intptr,intptr)
I ' m not sure what it says that I cannot access a disposed object, I ' m interacting with a list with a gesture detector, it ' s On-Screen, so it's not disposed.
Is this a bug in Xamarin.Forms?
On a similar note, if I modify the Mvvp property that notifies listeners the A property have changed (I always check it ' s O n the UI thread first), then if that's bound to a xamarin.forms list but it's not currently on-screen, presumably Xamarin. Forms would not barf? After-all it ' s just off-screen and should still bind okay?
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 has 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 and so you'll have a to add
<listview x:name= "Nostartlist" itemssource= "{Binding Pollingrecordinfos}" >
<ListViewCachingStrategy>RecycleElement</ListViewCachingStrategy>
</ListView>
This was actually the opposite of what @AdamP suggested ...
If you had 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 Reta Inelement, then I thought swapping to recycleelement might actually help.
Fingers crossed.
from:https://forums.xamarin.com/discussion/79315/ Xamarin-forms-bug-system-objectdisposedexception-cannot-access-a-disposed-object
Xamarin.Forms bug? System.ObjectDisposedException:Cannot Access a Disposed object