Bug 42785 - Unable to programmatically use NSToolbar
Summary: Unable to programmatically use NSToolbar
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 2.9.0
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Chris Hamons
Depends on:
Reported: 2016-07-25 14:42 UTC by Aaron Bockover [MSFT]
Modified: 2016-07-25 14:53 UTC (History)
1 user (show)

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

Test case (747 bytes, text/plain)
2016-07-25 14:42 UTC, Aaron Bockover [MSFT]

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 Aaron Bockover [MSFT] 2016-07-25 14:42:40 UTC
Created attachment 16778 [details]
Test case

Xamarin.Mac makes it impossible to build an NSToolbar programmatically, so it seems.

The attached NSWindowController subclass should display a toolbar with one item, but results in an exception:

System.InvalidOperationException: Event registration is overwriting existing delegate. Either just use events or your own delegate: NSToolbarBug.WindowController+ToolbarDelegate AppKit.NSToolbar+_NSToolbarDelegate
  at AppKit.NSApplication.EnsureDelegateAssignIsNotOverwritingInternalDelegate (System.Object currentDelegateValue, System.Object newDelegateValue, System.Type internalDelegateType) [0x0004a] in /Users/builder/data/lanes/3412/3cf8aaed/source/maccore/src/AppKit/NSApplication.cs:114
  at AppKit.NSToolbar.set_WeakDelegate (Foundation.NSObject value) [0x0000e] in /Users/builder/data/lanes/3412/3cf8aaed/source/maccore/src/build/mac/mobile/AppKit/NSToolbar.g.cs:566
  at AppKit.NSToolbar.set_Delegate (INSToolbarDelegate value) [0x00031] in /Users/builder/data/lanes/3412/3cf8aaed/source/maccore/src/build/mac/mobile/AppKit/NSToolbar.g.cs:327
  at NSToolbarBug.WindowController.WindowDidLoad () [0x00053] in /Users/aaron/Projects/NSToolbarBug/WindowController.cs:19
  at at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
  at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /Users/builder/data/lanes/3412/3cf8aaed/source/maccore/src/AppKit/NSApplication.cs:94
  at NSToolbarBug.MainClass.Main (System.String[] args) [0x00007] in /Users/aaron/Projects/NSToolbarBug/Main.cs:10
Comment 1 Aaron Bockover [MSFT] 2016-07-25 14:53:57 UTC
Ah, never mind. The delegate should be providing those default items. By setting the default items directly on the toolbar, I guess the toolbar creates an internal delegate that proxies them.