Bug 43931 - NSApplication.Init needs AppKit to be preloaded or it breaks
Summary: NSApplication.Init needs AppKit to be preloaded or it breaks
Status: CONFIRMED
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
URL:
Depends on:
Blocks:
 
Reported: 2016-09-01 10:20 UTC by Alan McGovern
Modified: 2016-09-26 21:58 UTC (History)
2 users (show)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and 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 Links.

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 for Bug 43931 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

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