I have a simple C# Application containing this line:
var mImage = System.Drawing.Image.FromFile(filename);
When running this code on Windows (.NET), the image is loaded correctly. When running the same code on OS X (Mono), the application just hangs. The debugger stays in that call forever. No exception no nothing.
The callstack shows the application hangs at:
System.Drawing.GDIPlus.GdiplusStartup ()
What could go wrong here?
PS: I have the latest versions of Xamarin Studio and Mono installed.
1) Not only check you have the latest Xamarin Studio version but check you have the latest build!!!
Bug report:
This problem was reported by Troy Dawson using Xamarin Studio Version 5.5 (build 198), just over a month ago: https://bugzilla.xamarin.com/show_bug.cgi?id=23444
"With the latest Mono from the alpha release channel, attached project should raise an typenotfound exception when run at:
var image = Image.FromStream(content);
Because GDIPlus can't be initialized or something.
This is similar to another bug I filed where Image.FromStream() takes a very long time to return when Mono is first run."
Full exception:
An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.Exception: GdiplusStartup
Solution:
A day after the bug was reported on 2014-09-29 Sadik Ali confirms he can reproduce the problem Comment 1, then 4 days later Troy Dawson confirms that Xamarin Studio Version 5.5 (build 227) fixes the issue Comment 2.
The problem is MonoMac GDI's way of interfacing with Mac fonts. The first time it is launched, it builds a font-cache it needs, and this actually takes a few minutes. Just let it run for a while. This delay goes away once the font cache is built.
If you kill it, it never finishes building the cache, and it'll happen every time. It's a shame they don't even yet have any kind of dialog or message printed that this is happening.
In rare situations, your font-cache directory may not be writable by mono. In this case, you can either run the app as root once, or you can follow the instructions here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With