Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
In this situation, our code has a NSWindow.ContentView which has set WantsLayer to true. At a later point, a subview is replaced with a different (newly created) subview. During the call to NSView.ReplaceSubview(), our override of set_Layer crashes with ArgumentNullException (which seems to be by design):
MonoMac.AppKit.NSView.set_Layer (Parameters=) in /cvs/monomac/src/AppKit/NSView.g.cs:2253
NationalInstruments.Core.Controls.NSViewBase.set_Layer (Parameters=) in /Users/steveno/projects/NextGen/R2/PlatformFramework/Dev-ToolViewModels/Core/Core/Controls/NSViewBase.MonoMac.cs:57
object.[NationalInstruments.Core.Controls.NSViewBase:Void set_Layer(MonoMac.CoreAnimation.CALayer)] (Parameters=) in
MonoMac.AppKit.NSView.ReplaceSubviewWith (Parameters=) in /cvs/monomac/src/AppKit/NSView.g.cs:468
Questions / Notes:
1. Have not tried this with MonoMac 3.0 yet, so we're not sure if this behavior has changed.
2. The ArgumentNullException does not occur (or is not visible to our code) when we do not override the Layer property. Presumably, the operation may still be occurring, but is handled internally by MonoMac.AppKit.
3. Is simply not calling base.set_Layer() the appropriate behavior when the system attempts to assign a null CALayer? (None of our code ever explicitly assigns a null CALayer.)
4. Are there ramifications w.r.t. "leaking" any objects?
Can you provide a code snippet that shows what you are doing?
Created attachment 2284 [details]
Project that reproduces crash on set_Layer w/ null value.
Build and run the attached project. Click the button in the lower left (Replace a View). It will crash in the set_Layer override on the NSView subclass.
Fixed on git