Bug 35392 - System.ArgumentException'jobject' must not be IntPtr.Zero. Parameter name: jobject when changing MenuItem IsEnabled
Summary: System.ArgumentException'jobject' must not be IntPtr.Zero. Parameter name: jo...
Status: RESOLVED NORESPONSE
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.5.1
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-10-30 07:31 UTC by Caan Mee
Modified: 2017-06-17 01:14 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description Caan Mee 2015-10-30 07:31:41 UTC
I noticed an error when changing IsEnabled of a MenuItem when the app was backgrounded and shortly after that resumed.


1) Start the app (do not wait for it to finish launching), press as soon you started the app the home button on your phone

2) When the app was backgrounded, try to start it again

3) After resuming from background, I get the following exception:

System.ArgumentException'jobject' must not be IntPtr.Zero. Parameter name: jobject
Android.Runtime.JNIEnv.CallObjectMethod(IntPtr jobject, IntPtr jmethod)
Android.Views.View.get_Context()
Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.UpdateMenu()
Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.HandleToolbarItemPropertyChanged(object sender, PropertyChangedEventArgs e)
Xamarin.Forms.BindableObject.OnPropertyChanged(string propertyName)
Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, bool silent)
Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, object value, SetValueFlags attributes)
Xamarin.Forms.MenuItem.set_IsEnabledCore(bool value)
Xamarin.Forms.MenuItem.OnCommandCanExecuteChanged(object sender, EventArgs eventArgs)
Xamarin.Forms.Command.ChangeCanExecute()
MyApp.MyViewModel.ChangeMenuItemEnabled()
Comment 1 Caan Mee 2015-10-30 07:32:27 UTC
Ah and "ChangeMenuItemEnabled" is called in OnAppearing of the Page
Comment 2 Shane 2016-03-25 18:29:23 UTC
I'm getting the same exception when I try to change the text of a menu item .. It's part of a set of operations (user logging out) where I remove a menu item and then change the text of a different menu item... It seems like something in the orchestration of that causes this exception.. If I put a delay on setting the text by like 5 seconds I never get the exception

System.Exception: CustomNavigationPage.ToolbarItem:Login ---> System.ArgumentException: 'jobject' must not be IntPtr.Zero.
Parameter name: jobject
  at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod) [0x00010] in /Users/builder/data/lanes/2970/46c3f7e0/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:170 
  at Android.Views.View.get_Context () [0x0002d] in /Users/builder/data/lanes/2970/46c3f7e0/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:4891 
  at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.UpdateMenu () [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.HandleToolbarItemPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00045] in <filename unknown>:0 
  at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00012] in <filename unknown>:0 
  at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindablePropertyContext context, System.Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) [0x000fb] in <filename unknown>:0 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) [0x0014b] in <filename unknown>:0 
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, Boolean fromStyle, Boolean checkAccess) [0x0005f] in <filename unknown>:0 
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.MenuItem.set_Text (System.String value) [0x00000] in <filename unknown>:0
Comment 3 Rui Marinho 2016-06-28 15:12:16 UTC
Thank you for taking the time to submit the bug. We tried to reproduce the issue you reported but were unable given the description. If you could please attach a reproduction to the bug by starting with a clean Xamarin.Forms project and adding just the code necessary to demonstrate the issue, we would very much appreciate it. 

For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d

Warm regards,
Xamarin Forms Team
Comment 4 David Ortinau [MSFT] 2017-06-17 01:14:59 UTC
Because we have not received a reply to our request for more information we are closing this issue. If you are still encountering this issue, please reopen the ticket with the requested information. Thanks!