SlideOverKit - Cannot access a disposed object SlideOverKit.Droid.SlideMenuDroidRenderer

JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭

I've got a problem using the SlideOverKit SlideMenu.

It works fine in general, with the following code in my xaml.cs:

namespace MyProject.UI.Pages
{
    public partial class EvacuationPage : MenuContainerPage
    {
        public EvacuationPage()
        {
            InitializeComponent();
            this.SlideMenu = new MyProjectMenuView();
        }
        protected override void OnAppearing()
        {
            base.OnAppearing();
            MessagingCenter.Subscribe<EvacuationPageModel>(this, MessagingConstants.MusterMenuShow, (sender) => {
                ShowMenu();
            });
        }

        protected override void OnDisappearing()
        {
            base.OnDisappearing();
            MessagingCenter.Unsubscribe<Evacuation>(this, MessagingConstants.MusterMenuShow);
        }

        protected override bool OnBackButtonPressed ()
        {
            MyProjectBasePageModel Model = (MyProjectBasePageModel)this.BindingContext;
            if (Model.CannotNavigateBackFrom) {
                return true;
            } else {
                return base.OnBackButtonPressed ();
            }
        }
    }
}

However, I'm occasionally getting the exception:

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)

Clearly the renderer is being disposed, and the code is then trying to access the disposed object.

One thing which may be relevant - but I can't tie the error down to when I'm doing this - is that I am calling RemoveFromNavigation to clear down the navigation stack.

Has anyone else seen this or got any idea what the problem might be?

Sign In or Register to comment.