Jan
Jan

Reputation: 4516

Reason why NSScreen.screens might return null with MonoMac?

I'm doing some Interop with native Mac libraries using the Mono/Monomac frameworks. Generally, it works well but now I need to find the screen resolution. Monomac has the necessary imports for NSScreen already defined.

Unfortunately, all of the properties on NSScreen (Screens, MainScreen and DeepestScreen) all return null. I was inclined to believe they never worked at all but I've seem them referenced in the source for MonoDevelop so it is likely that I am overlooking something. A code sample for completeness (the exception throws):

NSScreen[] shouldNotBeNull = NSScreen.Screens;
if (shouldNotBeNull == null)
    throw new Exception("That was unexpected");

I experimented with IntPtr scrRef = objc_getClass("NSScreen") as well, and in this case, scrRef also ends up being null (well, IntPtr.Zero). Coincidence or a clue?

Edit: stock Mono 2.10.9 on OSX 10.7.4

Upvotes: 2

Views: 221

Answers (1)

Jan
Jan

Reputation: 4516

Turns out NSApplication.Init() was not being called on this path.

Upvotes: 0

Related Questions