Bug 43931 - NSApplication.Init needs AppKit to be preloaded or it breaks
Summary: NSApplication.Init needs AppKit to be preloaded or it breaks
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) (show other bugs)
Version: Master
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-09-01 10:20 UTC by Alan McGovern
Modified: 2016-09-26 21:58 UTC (History)
2 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:


Description Alan McGovern 2016-09-01 10:20:21 UTC
1) Create a normal console application, reference the desktop Xamarin.Mac.dll and make sure libxammac.dylib is local copied.

2) Invoke `NSApplication.Init (); Console.WriteLine (NSApplication.SharedApplication)`

Result: shared application will be null. The reason is that the class pointer is null because AppKit was not loaded when the static constructor for NSApplication ran [0]. We either need to ensure the appkit framework has loaded before we get the class handle for NSApplication, or we need to reload the class handle after we load libxammac.dylib (which ensures App/kit loads as iy is a dependency).

If we want to refresh the handle as part of NSApplications.Init we just have to be careful that our initialisation does not indirectly require that handle to exist.

[0] https://github.com/xamarin/xamarin-macios/blob/2edb2ae4f5bb371a7006731987717c01f8725420/src/AppKit/NSApplication.cs#L39-L41

Note You need to log in before you can comment on or make changes to this bug.