Bug 21680 - NSToolbar crashes (ArgumentNullException) when programmatically populating toolbar
Summary: NSToolbar crashes (ArgumentNullException) when programmatically populating to...
Status: RESOLVED FIXED
Alias: None
Product: MonoMac
Classification: Desktop
Component: Bindings ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-07-30 01:02 UTC by xamarin
Modified: 2015-02-18 15:00 UTC (History)
3 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 FIXED

Description xamarin 2014-07-30 01:02:28 UTC
When programmatically populating a toolbar, if you do not explicitly assign a value to the SelectableItemIdentifiers member of NSToolbar, then the application will crash with an ArgumentNullException when 'activating' the command.

As a workaround, allocate an empty string array *WHICH WILL NOT BE GC'd*. (Or, allocate an array that contains the toolbar item identifiers that should be selectable.)

Example exception:

System.ArgumentNullException: Argument cannot be null.
Parameter name: items
  at at MonoMac.Foundation.NSArray.FromStrings (string[]) <IL 0x00011, 0x0008f>
  at at (wrapper dynamic-method) object.[MonoMac.AppKit.NSToolbar+_NSToolbarDelegate.System.String[] SelectableItemIdentifiers(MonoMac.AppKit.NSToolbar)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.AppKit.NSToolbar) <IL 0x00016, 0x0006f>
  at at (wrapper native-to-managed) object.[MonoMac.AppKit.NSToolbar+_NSToolbarDelegate.System.String[] SelectableItemIdentifiers(MonoMac.AppKit.NSToolbar)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.AppKit.NSToolbar) <IL 0x0006f, 0x0018b>
  at at (wrapper managed-to-native) MonoMac.ObjCRuntime.Messaging.void_objc_msgSendSuper_IntPtr (intptr,intptr,intptr) <0x00012>
  at at MonoMac.AppKit.NSApplication.SendEvent (MonoMac.AppKit.NSEvent) <IL 0x00051, 0x00163>
  at INTV.Shared.Utility.SingleInstanceApplication.SendEvent (MonoMac.AppKit.NSEvent) [0x00003] in /Users/steveno/Desktop/Projects/INTV.Shared/Utility/SingleInstanceApplication.Mac.cs:84
  at at (wrapper dynamic-method) object.[INTV.Shared.Utility.SingleInstanceApplication.Void SendEvent(MonoMac.AppKit.NSEvent)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.AppKit.NSEvent) <IL 0x00011, 0x00062>
  at at (wrapper native-to-managed) object.[INTV.Shared.Utility.SingleInstanceApplication.Void SendEvent(MonoMac.AppKit.NSEvent)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.AppKit.NSEvent) <IL 0x0006c, 0x0017f>
  at at (wrapper managed-to-native) MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[]) <0x00012>
  at at MonoMac.AppKit.NSApplication.Main (string[]) <IL 0x00041, 0x00103>
  at at INTV.Shared.Utility.SingleInstanceApplication.RunApplication<Locutus.View.MainWindow> (string,System.Configuration.ApplicationSettingsBase,string[],string) <0x00047>
  at Locutus.View.MainClass.Main (string[]) [0x00013] in /Users/steveno/Desktop/Projects/Locutus/Locutus/Main.cs:16
Comment 1 xamarin 2014-07-30 01:11:39 UTC
Previous comment about empty array not being gc'd is bogus. You just need to explicitly assign a delegate that returns an empty array (or one of your choosing).
Comment 2 Timothy Risi 2015-02-18 14:47:47 UTC
I ahve been unable to reproduce this crash so far, so I'm going to go ahead and close it as fixed.  If you're still running into issues, could you reopen it and provide a simple repro case?
Comment 3 Chris Hamons 2015-02-18 15:00:00 UTC
Steve,

Apologies on the delay in response. Some of these MonoMac bugs were overlooked when we were scrubbing for items to fix / respond to. Try it with Xamarin.Mac 1.10 (we have a trial now, so you can test it out without purchase) and let me know (chris.hamons@xamarin.com) if you are running into more issues.

-- Chris H