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.
original reporter: firstname.lastname@example.org
I discovered this bug while switching over from Storyboards to *.XIB files.
The method NSBundle.LoadNib(string, NSObject, NSDictionary) incorrectly throws an exception when passing NULL as the value of the second parameter (file owner). This constraint prevents the method from being used to load a UIView object from a XIB file without a UIViewController or other owner type.
Fortunately, I have sufficient access to work around the wrapper:
Selector selector = new Selector("loadNibNamed:owner:options:");
IntPtr stringPtr = NSString.CreateNative("MyUIViewXib");
NSArray result = (NSArray)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSendSuper_IntPtr_IntPtr_IntPtr(NSBundle.MainBundle.SuperHandle, selector.Handle, stringPtr, IntPtr.Zero, IntPtr.Zero));
You may recognize the code since it is taken directly from within the wrapper method. The only real different is that I am passing IntPtr.Zero for the owner instead. The resulting NSArray contains an instance of my custom UIView as the first entry.
UIView myView = (UIView)Runtime.GetNSObject(result.ValueAt(0));
LoadNib() should be changed to allow null parameters. Until then I will have to write code like above and I don’t know what the impact on other developers will be. Already, there is a lot of misinformation on the internet about how to load UIViews from XIB files.
*** This bug has been marked as a duplicate of bug 10136 ***