[Mono-osx] NullReferenceExceptions due to MonoMac.ObjCRuntime.GetNSObject()

Dan Fry dan at sonocent.com
Tue May 3 11:09:37 EDT 2011


Hi,

I'm currently using MonoMac to port a Windows application to Mac OS X. 
Recently I've started building MonoMac myself from the sources on 
github, and had started to get NullReferenceExceptions at seemingly 
random times.

The cause was apparently 
MonoMac.ObjCRuntime.Runtime.GetNSObject(IntPtr), which was changed a 
while ago to return null if the WeakReference to the managed NSObject 
held in the object_map has been garbage collected - see this commit:

https://github.com/mono/monomac/commit/2482fd3eef1ac5825146456a5b9c99ec7609fee6

The commit message says that it is OK to return null because the callers 
check for it, but as far as I can tell this does not seem to be the 
case. NSArray.ArrayFromHandle(IntPtr) is one example, but 
GetNSObject(IntPtr) is public so I presume any application code could 
call it and expect not to get null back.

I managed to fix the problem in my application by changing 
monomac/src/ObjCRuntime/Runtime.cs as shown in the attached diff.

I searched the bug database and the web and couldn't find any reference 
to this problem, which surprised me and made me wonder if I'm doing 
something wrong - I'm a complete newbie when it comes to git(hub)!

I'm not sure of the correct procedure for dealing with problems like 
this - should I submit a bug report? (I'm not sure whether that's only 
for official releases)

Thanks for your patience, any help would be greatly appreciated!

Dan


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20110503/175c3a69/attachment.html 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Runtime.cs.txt
Url: http://lists.ximian.com/pipermail/mono-osx/attachments/20110503/175c3a69/attachment.txt 


More information about the Mono-osx mailing list