Bug 7962 - Regression: Creating a System.Windows.Forms.Form() crashes on Mac on Mono 3.0
Summary: Regression: Creating a System.Windows.Forms.Form() crashes on Mac on Mono 3.0
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: Windows.Forms ()
Version: master
Hardware: Macintosh Mac OS
: Lowest normal
Target Milestone: Community
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-10-24 05:49 UTC by Ben Winkel
Modified: 2017-09-01 11:56 UTC (History)
9 users (show)

Tags: mono-community
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 7962 on GitHub or Developer Community 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: GitHub Markdown or Developer Community HTML
  • 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:
NEW

Description Ben Winkel 2012-10-24 05:49:54 UTC
System.Windows.Forms.Form() crashes on Mono 3.0 on MacOS Leopard. It doesn't fail on Mono 2.10.9. 

Simple repro program below (C# console app):

---------------------------


using System;

namespace Test
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Console.WriteLine ("Hello World!");
            var f = new System.Windows.Forms.Form();
            System.Windows.Forms.Application.Run(f);
        }
    }
}

----------------------------


Output:


Hello World!

Unhandled Exception:
System.ArgumentException: The requested FontFamily could not be found [GDI+ status: FontFamilyNotFound]
  at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0 
  at System.Drawing.FontFamily..ctor (GenericFontFamilies genericFamily) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Drawing.FontFamily:.ctor (System.Drawing.Text.GenericFontFamilies)
  at System.Drawing.FontFamily.get_GenericSansSerif () [0x00000] in <filename unknown>:0 
  at System.Drawing.Font.CreateFont (System.String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte charSet, Boolean isVertical) [0x00000] in <filename unknown>:0 
  at System.Drawing.Font..ctor (System.String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont) [0x00000] in <filename unknown>:0 
  at System.Drawing.Font..ctor (System.String familyName, Single emSize, System.String systemName) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Drawing.Font:.ctor (string,single,string)
  at System.Drawing.SystemFonts.get_DefaultFont () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Theme.get_DefaultFont () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.get_DefaultFont () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.get_Font () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Form..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Form:.ctor ()
  at Test.MainClass.Main (System.String[] args) [0x0000b]

[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: The requested FontFamily could not be found [GDI+ status: FontFamilyNotFound]
  at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0 
  at System.Drawing.FontFamily..ctor (GenericFontFamilies genericFamily) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Drawing.FontFamily:.ctor (System.Drawing.Text.GenericFontFamilies)
  at System.Drawing.FontFamily.get_GenericSansSerif () [0x00000] in <filename unknown>:0 
  at System.Drawing.Font.CreateFont (System.String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte charSet, Boolean isVertical) [0x00000] in <filename unknown>:0 
  at System.Drawing.Font..ctor (System.String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont) [0x00000] in <filename unknown>:0 
  at System.Drawing.Font..ctor (System.String familyName, Single emSize, System.String systemName) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Drawing.Font:.ctor (string,single,string)
  at System.Drawing.SystemFonts.get_DefaultFont () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Theme.get_DefaultFont () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.get_DefaultFont () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.get_Font () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Form..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Form:.ctor ()
Comment 1 Ben Winkel 2012-12-09 15:02:42 UTC
Any news on this? Is there any workaround, like installing some extra fonts?
Comment 2 Andrew Bacon 2012-12-13 16:27:24 UTC
Hi Ben,

Try installing XQuartz.

Thanks,
Andrew
Comment 3 Arlen Walker 2012-12-28 15:23:17 UTC
You might want to try it in 2.10.10, Ben.

I'm getting the exact same failure using KeePass on 2.10.10, and yes, I have xQuartz installed. OS version is Mountain Lion, and other X11 apps work fine, so that doesn't appear to be the problem. 2.10.9 doesn't have that issue (it has others, that I'm trying to figure out at the moment).
Comment 4 Anonymous 2013-01-05 00:24:35 UTC
This is not anything new really, this has been reported in the newgroup all the way back to Jan 2008.

http://mono.1490590.n4.nabble.com/running-winforms-application-on-OS-X-td1541632.html

I have run into this today on my Mac, and if that thread is correct it seems to be related to mono trying to get the font "MS Sans Serif" (font.c -> GdipGetGenericFontFamilySansSerif) and of course this doesn't exist on Mac, and I believe Microsoft removed it from Windows 7 and higher. 

I have tried this on 2.10.9 and 3.0.2 and both have the same issue for me.

First it seems odd that a cross platform framework would be trying to get a font that only exists on Windows and only up to Windows Vista. 

Can we remove use of Microsoft specific fonts in Mono's WinForms and replace them with generic versions that are common on Mac and Linux?
Comment 5 EVV 2013-02-27 05:30:10 UTC
Hello,
has anyone found a solution or workaround for this issue?
I have installed Mono version 2.10.11 [MonoFramework-MRE-2.10.11.macos10.xamarin.x86.dmg] but it does not work to run the software (Duplicati) that requires Mono.
Thanks for your feedback.
Comment 6 Ben Winkel 2013-03-02 15:25:00 UTC
Installing xquartz worked for me
Comment 7 Adam Czauderna 2013-04-24 14:07:47 UTC
I have the exact same problem on Mono 2.10.12 on Mac OS X 10.8.3.
It is not a problem on Windows and Linux. 

Installing xquartz helped a little. At least it showed empty form and didn't crash, but it didn't display any controls in it. So, in the end it was not a final solution. Still, I don't like requesting users to install xquartz just for our application, without knowing what other implications xquartz may cause. It seems rather intrusive. 

Any other follow up on this from the mono team?
Comment 8 KevinBr 2014-09-21 12:22:47 UTC
I'm new to mono and have experienced a similar issue..
I am using mono v3.8.0 (btw, only --version gave me this info, whereas -v didn't work)

I started off with the basics, with my goal to use mono to run the latest version of KeePass (1.27 classic)

hello2.cs:
using System;
using System.Windows.Forms;

public class HelloWorld : Form
{
    static public void Main ()
    {
        Application.Run (new HelloWorld ());
    }

    public HelloWorld ()
    {
        Text = "Hello Mono World";
    }
}

The mcs function worked, generating an .exe file.
mcs hello2.cs -pkg:dotnet

However, when I try to run "mono hello2.exe" I get the error below:

I had latest version of XQuartz (v2.7.7) running but removing it (relogging back in, presumably to use native X11) did not seem to change the outcome.
I've tried using "term application" under XQ/X11 kicking off mono, and the normal term under mac osx utils/other folder, to no avail.

I think the "basics" could use some direct links to the forums where issues on the basic steps could be grouped by.

Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.WindowsFormsSynchronizationContext ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.ThemeEngine ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.ThemeWin32Classic ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.KnownColors ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.DllNotFoundException: libgdiplus.dylib
  at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
  at System.Drawing.GDIPlus..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Drawing.KnownColors..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Drawing.Color.get_Black () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ThemeWin32Classic..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Windows.Forms.ThemeEngine..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Windows.Forms.SystemInformation.get_MenuAccessKeysUnderlined () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:.ctor ()
  at System.Windows.Forms.WindowsFormsSynchronizationContext..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Windows.Forms.Control..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ScrollableControl..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ContainerControl..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Form..ctor () [0x00000] in <filename unknown>:0 
  at HelloWorld..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) HelloWorld:.ctor ()
  at HelloWorld.Main () [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.WindowsFormsSynchronizationContext ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.ThemeEngine ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.ThemeWin32Classic ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.KnownColors ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.DllNotFoundException: libgdiplus.dylib
  at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
  at System.Drawing.GDIPlus..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Drawing.KnownColors..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Drawing.Color.get_Black () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ThemeWin32Classic..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Windows.Forms.ThemeEngine..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Windows.Forms.SystemInformation.get_MenuAccessKeysUnderlined () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:.ctor ()
  at System.Windows.Forms.WindowsFormsSynchronizationContext..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Windows.Forms.Control..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ScrollableControl..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ContainerControl..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Form..ctor () [0x00000] in <filename unknown>:0 
  at HelloWorld..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) HelloWorld:.ctor ()
  at HelloWorld.Main () [0x00000] in <filename unknown>:0
Comment 9 Hin-Tak Leung 2014-11-09 06:19:27 UTC
"---> System.DllNotFoundException: libgdiplus.dylib"

Do you have a libgdiplus.dylib anywhere?