SlideOverKit - Cannot access a disposed object

JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭

I'm getting this error when I show my menu with the code:

        protected override void OnAppearing()
        {
            base.OnAppearing();
            MessagingCenter.Subscribe<EvacuationPageModel>(this, MessagingConstants.MusterMenuShow, (sender) => {
                ShowMenu();
            });
        }

The error details are:

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'SlideOverKit.Droid.SlideMenuDroidRenderer'.
at Java.Interop.JniPeerMembers.AssertSelf (IJavaPeerable self) [0x00030] in /Users/builder/data/lanes/3540/1cf254db/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.cs:153
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00002] in /Users/builder/data/lanes/3540/1cf254db/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:345
at Android.Views.View.Animate () [0x00000] in /Users/builder/data/lanes/3540/1cf254db/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:10701
at SlideOverKit.Droid.SlideOverKitDroidHandler+<>c__DisplayClass13_0.b__1 () [0x0001f] in C:\Users\Michael\Documents\SlideOverKit\SlideOverKit.Droid\SlideOverKitDroidHandler.cs:79
at SlideOverKit.MenuContainerPage.ShowMenu () [0x00008] in C:\Users\Michael\Documents\SlideOverKit\SlideOverKit\MenuContainerPage.cs:42
at Musterd.UI.Pages.EvacuationPage.m__0 (Musterd.UI.PageModels.EvacuationPageModel sender) [0x00002] in /Users/jameslavery/Documents/P4/THI/Musterd/src/dev_JGL/Musterd/UI/Pages/EvacuationPage.xaml.cs:25
at Xamarin.Forms.MessagingCenter+<>c__DisplayClass4_0`1[TSender].b__0 (System.Object sender, System.Object args) [0x00027] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Core\MessagingCenter.cs:54
at Xamarin.Forms.MessagingCenter.InnerSend (System.String message, System.Type senderType, System.Type argType, System.Object sender, System.Object args) [0x00069] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Core\MessagingCenter.cs:95
at Xamarin.Forms.MessagingCenter.Send[TSender] (Xamarin.Forms.TSender sender, System.String message) [0x00013] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Core\MessagingCenter.cs:23
at Musterd.UI.PageModels.EvacuationPageModel.ShowMusterMenu () [0x00007] in /Users/jameslavery/Documents/P4/THI/Musterd/src/dev_JGL/Musterd/UI/PageModels/EvacuationPageModel.cs:311
at Musterd.UI.PageModels.EvacuationPageModel.m__6 () [0x00001] in /Users/jameslavery/Documents/P4/THI/Musterd/src/dev_JGL/Musterd/UI/PageModels/EvacuationPageModel.cs:276
at Xamarin.Forms.Command+<>c__DisplayClass3_0.<.ctor>b__0 (System.Object o) [0x00000] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Core\Command.cs:36
at Xamarin.Forms.Command.Execute (System.Object parameter) [0x00000] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Core\Command.cs:70
at Xamarin.Forms.MenuItem.Xamarin.Forms.IMenuItemController.Activate () [0x00010] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Core\MenuItem.cs:93
at Xamarin.Forms.Platform.Android.GenericMenuClickListener.OnMenuItemClick (IMenuItem item) [0x00000] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\GenericMenuClickListener.cs:18
at Android.Views.IMenuItemOnMenuItemClickListenerInvoker.n_OnMenuItemClick_Landroid_view_MenuItem_ (IntPtr jnienv, IntPtr native__this, IntPtr native_item) [0x00011] in /Users/builder/data/lanes/3540/1cf254db/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.IMenuItem.cs:295
at at (wrapper dynamic-method) System.Object:ff93d8b2-826e-4fd0-a685-44820fe9a4de (intptr,intptr,intptr)

Looks like the renderer is being disposed Well, that's obvious from the error message!

One thing which might be relevant is that I'm using RemoveFromNavigation to clear down the navigation stack.

Any thoughts on how I can fix this?

Posts

  • AhmadRazaNazirAhmadRazaNazir USMember ✭✭

    @JamesLavery : I'm facing same issue in my app. Did you find any work around ?

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭

    I have found that the exception doesn't actually stop the menu working - so I just catch the exception but do nothing with it:

    protected override void OnAppearing()
            {
                base.OnAppearing();
                MessagingCenter.Subscribe<EvacuationPageModel>(this, MessagingConstants.MenuShow, (sender) => {
                    try {
                        ShowMenu();
                    } catch (Exception) {
                    }
                });
            }
    

    I should probably only ignore the exception if it's specific to the error in question.

  • ChasakisDChasakisD USMember ✭✭

    In my case, from a tabbedpage i navigated to a new page which has a slideoverkit menu. After going back and then back in, somehow the disposed object never unsubscribed from the messagingcenter so when a message comes from the viewmodel, it triggers 1 disposed page and 1 fresh.

    @JamesLavery So the solution is to implement the IDisposable on your "MenuContainerPage" and inside the Dispose method, unsubscribe from the message. In my case(i use Prism Navigation) i had to implement IDestructive.

  • rakeshraghavanrakeshraghavan INMember ✭✭
    When I upgraded to xamarin forms it's resolved my issues
  • ChasakisDChasakisD USMember ✭✭

    @rakeshraghavan I actually had this issue on the latest stable of X.F

  • divyagarimelladivyagarimella Member ✭✭

    @JameLavery
    i also faced same issue.now i have solved that problem .i think you need to do MessagingCenter.UnSubscribe in page disappearing event.

  • mannan_hmsolmannan_hmsol Member

    Thanks @divyagarimella . After unsubscribing messagingCenter on disappearing event it's worked for me.

Sign In or Register to comment.