xamarinxamarin.androidscrollviewobjectdisposedexception

SlidingMenuSharp System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Android.Widget.Scroller'


We have a Xamarin.Android 7 app. We are getting the following exception which causes the app to crash. It says something about Android.Widget.Scroller, but we are not using this component explicitly in our app anywhere. We are using ScrollView and GridView in xaml files though.

One solution which we came across was to move back to Xamarin.Android 6, but that is not a feasible solution due to app requirements. One more solution we came across was to use ListViewCachingStrategy, but couldn't find how to do that in Xamarin.Android.

Please help us out here, this is huge roadblock in our task.

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Android.Widget.Scroller'.
at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <5716a943049b49ca928a3a1c8d2386f4>:0 
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualBooleanMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <5716a943049b49ca928a3a1c8d2386f4>:0 
at Android.Widget.Scroller.get_IsFinished () [0x0000a] in <8804aaaf21bc4f45b576b50092b57059>:0 
at SlidingMenuSharp.CustomViewAbove.ComputeScroll () [0x00001] in <20b4998942db4089b3ed88297710fab6>:0 
at Android.Views.View.n_ComputeScroll (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <8804aaaf21bc4f45b576b50092b57059>:0 
at (wrapper dynamic-method) System.Object:0044ef4c-4a4e-4ecd-8301-8be4cc63baea (intptr,intptr)

Solution

  • Use the new GC Bridge vs. the default tarjan:

    MONO_GC_PARAMS=bridge-implementation=new
    

    Create an text file within your Xamarin.Android project and set a build type of AndroidEnvironment on it and include the MONO_GC_PARAMS line from above.

    Rebuild and test your project.

    Re: https://developer.xamarin.com/guides/android/advanced_topics/garbage_collection/#GC_Bridge_Options