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.
I'm attempting to use NSOutlineView with the Delegate/Datasource properties. Attached is a Objective-C and C# example program, with identical code. One works, one does not.
Created attachment 2029 [details]
Created attachment 2030 [details]
I forgot to mention in the original report, but the crash doesn't appear on launch. You have to resize the window for about 10 seconds to make it occur. It occurs 100% of the time on my machine.
Created attachment 2062 [details]
I've tracked down either a new issue or another example of the same root cause (I believe latter).
It appears that the delegate of NSOutlineView goes bad when both are true:
1) It is shoved in the visual tree:
2) GC.Collect() is then called.
The attached always crashes mono/monotouch/the app when CRASH is defined and never does when I keep an explicit reference around (CRASH not defined).
I fixed one part of the problem, which was that NSViews were not keeping a reference alive to the items below it. A workaround for you until you upgrade your MonoMac is to do something like:
static object retainer;
And add the variable "outline" to retainer.
The second problem is a bit more complicated, I can offer a solution for now, and I need to think more about it.
The two samples are actually different. The Objective-C one returns NSNumbers while the C# one returns a custom class. A simple fix is to return an NSNumber and then use an NSNumber later on, instead of the custom class.
Now if you want to use your wrapper, the problem is this: we create an object in managed code that contains the value, and return it to Objective-C. Objective-C takes a reference to it, and since we no longer need it, we garbage collect it.
Later, Objective-C surfaces the object back to managed code, but we already got rid of the object, so you get an exception that the constructor with type IntPtr does not exist.
So the options are:
(a) Keep a hashtable of all returned objects to Objective-C, so that they can be invoked back
(b) Encode in the NSNumber the data that you need to produce the data on demand.