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.
If a MonoMac type is created, but its constructor has never been called (for example, by calling a static method such as NSNumber.FromInt32()), an InvalidCastException is raised. This appears to be because an entry is only added to Class.type_map when a type's constructor is first called.
In addition, in the event that none of the constructors for the ancestors of the class have been called, Class.Lookup() enters an infinite loop. (This appears to have the same cause as bug 408).
This bug appears to be present in the latest revision of MonoMac in git, at the time of writing.
The attached project reproduces the bug but must be used with a build of MonoMac from git, as the version supplied with MonoDevelop 2.8.1 appears to cause the debugger to hang.
Created attachment 808 [details]
MD project to reproduce bug
You need to call:
in your console application, otherwise not everything will be initialized properly.
Also recent version (tried with Xamarin.Mac) won't enter an infinite loop, you'll get:
System.ArgumentException: Could not find a valid superclass for type __NSCFNumber. Did you forget to register the bindings at MonoMac.ObjCRuntime.Class.Register() or call NSApplication.Init()?
at MonoMac.ObjCRuntime.Class.Lookup (IntPtr klass) [0x000ab] in /Users/poupou/git/mono/xamcore/monomac/src/ObjCRuntime/Class.cs:118
which (hints you about the missing NSApplication.Init call).