Hello everyone.
I'm having an issue where I am getting crashes at seemingly random intervals when navigating between pages, this seems to be exclusive to the Android build.
First a a bit of background info:
- My app is using the latest version of Xamarin.Forms 4.7.
- I have attempted to use XAML and Bindings where possible, implementing the ViewModelLocator pattern.
- I have also disabled the FastRenderers because I utilize Grids to stack some views to get some of the desired effects.(
Xamarin.Forms.Forms.SetFlags("UseLegacyRenderers"
) - I also make use of what we call UserControls (ContentViews with XAML) to create reusable, simplified controls.
- Where possible values are assigned exclusively using Bindings.
- Anywhere where I have used an Effect or similar, I have made sure to include null checks wherever it seems appropriate.
- Navigation is handled using Navigation.PushAsync(page) for the most part.
- The issue in question only seems to happen when pushing or popping from the navigation stack.
- The app makes extensive use of CollectionViews
For the longest time, the crash only happened occasionally, and seemed infrequent enough that it could be comfortbly ignored, but now it seems to be happening almost every time I try to test the app. The actual trigger still seems random but it always happens when going between two pages, sometimes it triggers immediately, sometimes after a few tries.
It also, at first seemed to be exclusively linked to LabelRenderers, but has more recently also been linked to an ActivityIndicatorRenderer.
Here are a couple of the sorts of stack traces I'm getting:
[MonoDroid] System.ObjectDisposedException: Cannot access a disposed object. [MonoDroid] Object name: 'Xamarin.Forms.Platform.Android.LabelRenderer'. [MonoDroid] at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <26521a5118b44c858c385715922b9d5d>:0 [MonoDroid] at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <26521a5118b44c858c385715922b9d5d>:0 [MonoDroid] at Android.Views.View.get_Context () [0x0000a] in <4ccdb3137d974856b786e1aeebbfbab6>:0 [MonoDroid] at Xamarin.Forms.Platform.Android.Platform.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) [0x00019] in D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:1341 [MonoDroid] at Xamarin.Forms.Forms+AndroidPlatformServices.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\Forms.cs:921 [MonoDroid] at Xamarin.Forms.VisualElement.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00025] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:807 [MonoDroid] at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:790 [MonoDroid] at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:666 [MonoDroid] at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:724 [MonoDroid] at Xamarin.Forms.Grid.MeasuredStarredColumns (System.Double widthConstraint, System.Double heightConstraint) [0x000b3] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:453 [MonoDroid] at Xamarin.Forms.Grid.MeasureAndContractStarredColumns (System.Double width, System.Double height, System.Double totalStarsWidth) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:377 [MonoDroid] at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) [0x0010e] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:511 [MonoDroid] at Xamarin.Forms.Grid.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x0002a] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:60 [MonoDroid] at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:790 [MonoDroid] at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:666 [MonoDroid] at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:132 [MonoDroid] at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:724 [MonoDroid] at Xamarin.Forms.Grid.CalculateAutoCells (System.Double width, System.Double height) [0x000e5] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:133 [MonoDroid] at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) [0x0000c] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:485 [MonoDroid] at Xamarin.Forms.Grid.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x0002a] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:60 [MonoDroid] at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:790 [MonoDroid] at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:666 [MonoDroid] at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:132 [MonoDroid] at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:724 [MonoDroid] at Xamarin.Forms.TemplatedView.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x0003c] in D:\a\1\s\Xamarin.Forms.Core\TemplatedView.cs:43 [MonoDroid] at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:790 [MonoDroid] at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:666 [MonoDroid] at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:132 [MonoDroid] at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:724 [MonoDroid] at Xamarin.Forms.StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint) [0x000a8] in D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:163 [MonoDroid] at Xamarin.Forms.StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders) [0x00058] in D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:123 [MonoDroid] at Xamarin.Forms.StackLayout.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x0004e] in D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:58 [MonoDroid] at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266 [MonoDroid] at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224 [MonoDroid] at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:812 [MonoDroid] at Xamarin.Forms.Layout.ResolveLayoutChanges () [0x0005c] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:392 [MonoDroid] at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <4ccdb3137d974856b786e1aeebbfbab6>:0 [MonoDroid] at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <4ccdb3137d974856b786e1aeebbfbab6>:0 [MonoDroid] at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.48(intptr,intptr) [rocca.reps.rep] JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable [mono] Unhandled Exception: [mono-rt] at (wrapper native-to-managed) Android.Runtime.DynamicMethodNam07-14 10:20:20.035 E/mono (10423): System.ObjectDisposedException: Cannot access a disposed object. [mono] Object name: 'Xamarin.Forms.Platform.Android.LabelRenderer'. [mono] at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.48(intptr,intptr) [mono] at (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.48(intptr,intptr) [mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.ObjectDisposedException: Cannot access a disposed object. [mono-rt] Object name: 'Xamarin.Forms.Platform.Android.LabelRenderer'. [mono-rt] at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.48(intptr,intptr) [mono-rt] at (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.48(intptr,intptr)
[MonoDroid] UNHANDLED EXCEPTION: [MonoDroid] System.ObjectDisposedException: Cannot access a disposed object. [MonoDroid] Object name: 'Xamarin.Forms.Platform.Android.ActivityIndicatorRenderer'. [MonoDroid] at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in <26521a5118b44c858c385715922b9d5d>:0 [MonoDroid] at Xamarin.Forms.Platform.Android.Platform.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) [0x00019] in D:\a\1\s\Xamarin.Forms.Pl07-13 17:37:40.155 I/MonoDroid(14402): at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in <26521a5118b44c858c385715922b9d5d>:0 [MonoDroid] at Android.Views.View.get_Context () [0x0000a] in <4ccdb3137d974856b786e1aeebbfbab6>:0 [MonoDroid] at Xamarin.Forms.VisualElement.Measure (System.atform.Android\Platform.cs:1341 [MonoDroid] at Xamarin.Forms.Forms+AndroidPlatformServices.GetNativeSize (Xamarin.Forms.VisualElement view, System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\Forms.cs:921 [MonoDroid] at Xamarin.Forms.VisualElement.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00025] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:807 [MonoDroid] at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:790 [MonoDroid] at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:666 [MonoDroid] at Xamarin.Forms.TemplatedView.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x0003c] in D:\a\1\s\Xamarin.Forms.Core\TemplatedView.cs:43 [MonoDroid] at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:790 [MonoDroid] at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:666 [MonoDroid] at Xamarin.Forms.StackLayout.LayoutChildren (System.Double x, System.Double y, System.Double width, Sy07-13 17:37:40.155 I/MonoDroid(14402): at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:132 [MonoDroid] at Xamarin.Forms.StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint) [0x000a8] in D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:163 [MonoDroid] at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in 07-13 17:37:40.155 I/MonoDroid(14402): at Xamarin.Forms.StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders) [0x00058] in D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:123 [MonoDroid] at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266 [MonoDroid] at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224 [MonoDroid] at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:812 [MonoDroid] at Xamarin.Forms.Layout.ResolveLayoutChanges () [0x0005c] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:392 [MonoDroid] at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <4ccdb3137d974856b786e1aeebbfbab6>:0 [MonoDroid] at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <4ccdb3137d974856b786e1aeebbfbab6>:0 [MonoDroid] at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.48(intptr,intptr) [rocca.reps.rep] JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable [Mono] DllImport searching in: '__Internal' ('(null)'). [Mono] Searching for 'java_interop_jnienv_throw'. [Mono] Probing 'java_interop_jnienv_throw'. [Mono] Found as 'java_interop_jnienv_throw'. [mono] [mono] Unhandled Exception: [mono] System.ObjectDisposedException: Cannot access a disposed object. [mono] Object name: 'Xamarin.Forms.Platform.Android.ActivityIndicatorRenderer'. [mono] at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.48(intptr,intptr) [mono] at (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.48(intptr,intptr) [mono-rt] at (wrapper native-to-managed) Android.07-13 17:37:42.541 E/mono-rt (14402): [ERROR] FATAL UNHANDLED EXCEPTION: System.ObjectDisposedException: Cannot access a disposed object. [mono-rt] Object name: 'Xamarin.Forms.Platform.Android.ActivityIndicatorRenderer'. [mono-rt] at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.48(intptr,intptr) [mali_winsys] delete_surface() [1080x2280] return
Any help would be greatly appreciated!
Thanks