I get the following crash randomly (it feels like some race condition), when navigating back from a page with ScrollView, and 'ScrollToAsync' was recently called:
06-30 19:06:03.576 I/MonoDroid( 4318): System.ObjectDisposedException: Cannot access a disposed object.
06-30 19:06:03.576 I/MonoDroid( 4318): Object name: 'Xamarin.Forms.Platform.Android.ScrollViewRenderer'.
06-30 19:06:03.576 I/MonoDroid( 4318): at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in :0
06-30 19:06:03.576 I/MonoDroid( 4318): at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualBooleanMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in :0
06-30 19:06:03.576 I/MonoDroid( 4318): at Android.Views.View.get_IsLayoutRequested () [0x0000a] in :0
06-30 19:06:03.576 I/MonoDroid( 4318): at Xamarin.Forms.Platform.Android.ScrollViewRenderer+<OnScrollToRequested>d__44.MoveNext () [0x000ce] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\Renderers\ScrollViewRenderer.cs:251
06-30 19:06:03.576 I/MonoDroid( 4318): --- End of stack trace from previous location where exception was thrown ---
06-30 19:06:03.576 I/MonoDroid( 4318): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
06-30 19:06:03.576 I/MonoDroid( 4318): at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__6_0 (System.Object state) [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0
06-30 19:06:03.576 I/MonoDroid( 4318): at Android.App.SyncContext+<>c__DisplayClass2_0.b__0 () [0x00000] in :0
06-30 19:06:03.576 I/MonoDroid( 4318): at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in :0
06-30 19:06:03.576 I/MonoDroid( 4318): at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in :0
06-30 19:06:03.576 I/MonoDroid( 4318): at (wrapper dynamic-method) System.Object:bfb0b6b7-b01c-4530-b07b-f74cbcf65a2b (intptr,intptr)
06-30 19:06:03.609 W/art ( 4318): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
I suspect that by navigating away from the ContentPage, the ScrollViewRenderer gets disposed, and gets to handle one more event after that, but as it's already disposed - it crashes.
What would be your suggestion to work around this crash? I wasn't yet able to find any way to synchronize the moment to navigate away when it is guaranteed to be safe (the scrolling request completely handled)
This happens with Xamarin Forms versions 24.2.1 as well as the latest 25.3.1.
Would using a custom renderer, identical to the ScrollViewRenderer, but with 'overriden' dispose method, in order to try to stay in memory, help workaround this issue?