Bug 42791 - NSWindowController.Document should allow setting null
Summary: NSWindowController.Document should allow setting null
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: Master
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Chris Hamons
Depends on:
Reported: 2016-07-25 19:54 UTC by Aaron Bockover [MSFT]
Modified: 2016-07-25 20:40 UTC (History)
1 user (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 Aaron Bockover [MSFT] 2016-07-25 19:54:11 UTC
@interface NSWindowController
  @property(assign) id document

We are missing a [NullAllowed] in our binding.

> The value of this property is nil if no document is associated with the window. When a window controller is added to a document's list of window controllers, the document uses this property to set the window controller’s document; you should not set this property. AppKit uses this property to access the document for relevant next-responder messages.

While this should not be set from user code, if you are overriding the property in managed code to intercept AppKit's setting of the document, it is appropriate to proxy the value (null or otherwise) to the base instance, which is not currently possible with a null value.

AppKit will set this property to null when closing the window.

	public override NSDocument Document {
		get { return base.Document; }
			set {
			// bad citizen, but avoids XM exception
			if (value == null)

			base.Document = value;

			DoSomethingWithDocument ();
Comment 1 Aaron Bockover [MSFT] 2016-07-25 19:59:30 UTC
Comment 2 Chris Hamons 2016-07-25 20:40:49 UTC
Landed in master.