System.ArgumentException: Handle must be valid. Parameter name: instance while navigating backwards

I have a main page which is a MasterDetailPage, Detail page of which is set as:
Detail = new NavigationPage(new ContentPage())

Then I navigate to ContentPage -> ListPage
On ListPage I have an image which has a tapGestureRecognizer. drillTapped command is executed every time user taps the Image. Inside this command, I am navigating to another page.

                private void OnDrill(object obj)
                    {
                            Navigation.PushAsync(new HomePage((obj as chartObject)));
                }

So my Navigation now is:
ContentPage -> ListPage -> HomePage
Everything works fine as expected. and chart can be seen on HomePage.

When I press Back Button on Navigation Bar, I Navigate back to ListPage. NOW if I press back, I should Navigate Back to ContentPage But I am getting following Exception.

UNHANDLED EXCEPTION: System.ArgumentException: Handle must be valid. Parameter name: instance at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method) [0x00017] in /Users/builder/data/lanes/4009/3a62f1ea/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:11650 at Android.Runtime.JNIEnv.CallNonvirtualObjectMethod (System.IntPtr jobject, System.IntPtr jclass, System.IntPtr jmethod) [0x00000] in /Users/builder/data/lanes/4009/3a62f1ea/source/monodroid/src/Mono.Android/JNIEnv.g.cs:276 at Com.Syncfusion.Charts.SfChart.get_PrimaryAxis () [0x00075] in <7214c1e575e942b98a604e773eb60d00>:0 at Syncfusion.SfChart.XForms.Droid.Disposer.DisposeNativeContents (Syncfusion.SfChart.XForms.SfChart sfChart) [0x0001c] in <34661f52d3f246459037fafce7510c25>:0 at Syncfusion.SfChart.XForms.Droid.Disposer.Dispose (Syncfusion.SfChart.XForms.SfChart sfChart) [0x00000] in <34661f52d3f246459037fafce7510c25>:0 at Syncfusion.SfChart.XForms.Droid.SfChartRenderer.Dispose (System.Boolean disposing) [0x00015] in <34661f52d3f246459037fafce7510c25>:0 at Java.Lang.Object.Dispose () [0x00000] in /Users/builder/data/lanes/4009/3a62f1ea/source/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:203 at Xamarin.Forms.Platform.Android.VisualElementRenderer ``1[TElement].Dispose (System.Boolean disposing) [0x000b3] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:262 at Java.Lang.Object.Dispose () [0x00000] in /Users/builder/data/lanes/4009/3a62f1ea/source/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:203 at Xamarin.Forms.Platform.Android.VisualElementRenderer ``1[TElement].Dispose (System.Boolean disposing) [0x000b3] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:262 at Java.Lang.Object.Dispose () [0x00000] in /Users/builder/data/lanes/4009/3a62f1ea/source/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:203 at Xamarin.Forms.Platform.Android.VisualElementRenderer ``1[TElement].Dispose (System.Boolean disposing) [0x000b3] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:262 at Java.Lang.Object.Dispose () [0x00000] in /Users/builder/data/lanes/4009/3a62f1ea/source/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:203 at Xamarin.Forms.Platform.Android.ScrollViewContainer.Dispose (System.Boolean disposing) [0x00013] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\Renderers\ScrollViewContainer.cs:49 at Java.Lang.Object.Dispose () [0x00000] in /Users/builder/data/lanes/4009/3a62f1ea/source/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:203 at Xamarin.Forms.Platform.Android.ScrollViewRenderer.Dispose (System.Boolean disposing) [0x00029] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\Renderers\ScrollViewRenderer.cs:156 at Java.Lang.Object.Dispose () [0x00000] in /Users/builder/data/lanes/4009/3a62f1ea/source/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:203 at Xamarin.Forms.Platform.Android.VisualElementRenderer ``1[TElement].Dispose (System.Boolean disposing) [0x000b3] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:262 at Xamarin.Forms.Platform.Android.PageRenderer.Dispose (System.Boolean disposing) [0x00011] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\Renderers\PageRenderer.cs:20 at Java.Lang.Object.Dispose () [0x00000] in /Users/builder/data/lanes/4009/3a62f1ea/source/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:203 at Xamarin.Forms.Platform.Android.AppCompat.FragmentContainer.OnDestroyView () [0x0003f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\FragmentContainer.cs:90 at Android.Support.V4.App.Fragment.n_OnDestroyView (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <7a2a36256f1648ecbd0c15a75bc5a349>:0 at (wrapper dynamic-method) System.Object:ad8e1634-b787-479f-a839-e167f50bda3f (intptr,intptr)

However if i do following, I don't get any exception in navigating all the way to rootPage and no exception is seen:
private void OnDrill(object obj)
{
Navigation.PushAsync(new HomePage());
}
As i can guess by reading Dispose() , This is appearing while destroying some object but I am not sure which..
Can anybody help me to understand the problem and possibly suggest some solutions or workaround?

Sign In or Register to comment.