Bug 46162 - NSMenu.IndexOfItem binding error
Summary: NSMenu.IndexOfItem binding error
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: Master
Hardware: PC Mac OS
: Normal normal
Target Milestone: (C9)
Assignee: Bugzilla
Depends on:
Reported: 2016-10-28 19:27 UTC by Sandy Armstrong [MSFT]
Modified: 2016-11-22 10:35 UTC (History)
5 users (show)

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:

Description Sandy Armstrong [MSFT] 2016-10-28 19:27:04 UTC
Version: (Visual Studio Enterprise)

`NSMenu.IndexOfItem(NSObject target, Selector actionSelector)` appears to be bound incorrectly. Apple documentation says that `target` can be `nil`, but if I pass `null` along with any non-null selector, an ArgumentNullException is raised for the `target` parameter.

Try the following in a Mac workbook to reproduce:

    NSApplication.SharedApplication.MainMenu.IndexOfItem (null, new ObjCRuntime.Selector("quit:"))
Comment 1 Chris Hamons 2016-10-28 21:02:03 UTC
Comment 4 Timothy Risi 2016-11-21 21:01:27 UTC
Hi Sachin,

The reason you're getting the NullReferenceException there is because at the point you're trying to call NSApplication.SharedApplication.MainMenu.IndexOfItem in the Main method there, MainMenu is still null (So you're trying to call a method on a null object).  If you move your call into the AppDelegate's DidFinishLaunching method, it works fine.