全新安装后在测试Hello World代码时无法运行“ System.Windows.Forms应用程序”

时间:2019-08-19 04:49:13

标签: c# linux mono

我是Linux(Slackware 14.2)用户,需要在我的计算机上为工作项目安装 mono 。安装slackbuild之后,我从https://www.mono-project.com/docs/getting-started/mono-basics/运行了代码,效果很好,直到我尝试如下使用' System.Windows.Forms '

using System;
using System.Windows.Forms;

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

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

编译并运行后,我得到:

$ mono hello.exe 

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'System.Windows.Forms.WindowsFormsSynchronizationContext' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Windows.Forms.ThemeEngine' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Windows.Forms.ThemeWin32Classic' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Drawing.KnownColors' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Drawing.GDIPlus' threw an exception. ---> System.DllNotFoundException: libgdiplus.so.0
  at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
  at System.Drawing.GDIPlus..cctor () [0x000ab] in <ac0a7ab7ad9c4534aa7b9d68ccc688c1>:0 
   --- End of inner exception stack trace ---
  at System.Drawing.KnownColors..cctor () [0x0001a] in <ac0a7ab7ad9c4534aa7b9d68ccc688c1>:0 
   --- End of inner exception stack trace ---
  at System.Drawing.Color.get_Black () [0x00000] in <ac0a7ab7ad9c4534aa7b9d68ccc688c1>:0 
  at System.Windows.Forms.ThemeWin32Classic..cctor () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
   --- End of inner exception stack trace ---
  at System.Windows.Forms.ThemeEngine..cctor () [0x0002f] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
   --- End of inner exception stack trace ---
  at System.Windows.Forms.SystemInformation.get_MenuAccessKeysUnderlined () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
  at System.Windows.Forms.Control..ctor () [0x000e4] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:.ctor ()
  at System.Windows.Forms.WindowsFormsSynchronizationContext..cctor () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
   --- End of inner exception stack trace ---
  at System.Windows.Forms.Control..ctor () [0x00014] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
  at System.Windows.Forms.ScrollableControl..ctor () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
  at System.Windows.Forms.ContainerControl..ctor () [0x0000e] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
  at System.Windows.Forms.Form..ctor () [0x00012] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
  at HelloWorld..ctor () [0x00000] in <ebd84f70eef34e1bac9228a36ebc3550>:0 
  at (wrapper remoting-invoke-with-check) HelloWorld:.ctor ()
  at HelloWorld.Main () [0x00001] in <ebd84f70eef34e1bac9228a36ebc3550>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'System.Windows.Forms.WindowsFormsSynchronizationContext' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Windows.Forms.ThemeEngine' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Windows.Forms.ThemeWin32Classic' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Drawing.KnownColors' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Drawing.GDIPlus' threw an exception. ---> System.DllNotFoundException: libgdiplus.so.0
  at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
  at System.Drawing.GDIPlus..cctor () [0x000ab] in <ac0a7ab7ad9c4534aa7b9d68ccc688c1>:0 
   --- End of inner exception stack trace ---
  at System.Drawing.KnownColors..cctor () [0x0001a] in <ac0a7ab7ad9c4534aa7b9d68ccc688c1>:0 
   --- End of inner exception stack trace ---
  at System.Drawing.Color.get_Black () [0x00000] in <ac0a7ab7ad9c4534aa7b9d68ccc688c1>:0 
  at System.Windows.Forms.ThemeWin32Classic..cctor () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
   --- End of inner exception stack trace ---
  at System.Windows.Forms.ThemeEngine..cctor () [0x0002f] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
   --- End of inner exception stack trace ---
  at System.Windows.Forms.SystemInformation.get_MenuAccessKeysUnderlined () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
  at System.Windows.Forms.Control..ctor () [0x000e4] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:.ctor ()
  at System.Windows.Forms.WindowsFormsSynchronizationContext..cctor () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
   --- End of inner exception stack trace ---
  at System.Windows.Forms.Control..ctor () [0x00014] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
  at System.Windows.Forms.ScrollableControl..ctor () [0x00000] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
  at System.Windows.Forms.ContainerControl..ctor () [0x0000e] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
  at System.Windows.Forms.Form..ctor () [0x00012] in <cfc91f7a5a0243dda6f0da9f9f2bd749>:0 
  at HelloWorld..ctor () [0x00000] in <ebd84f70eef34e1bac9228a36ebc3550>:0 
  at (wrapper remoting-invoke-with-check) HelloWorld:.ctor ()
  at HelloWorld.Main () [0x00001] in <ebd84f70eef34e1bac9228a36ebc3550>:0 

我做错了(或没做过)吗?

1 个答案:

答案 0 :(得分:0)

没有注意到我安装了32位库。现在完美工作。
谢谢Stefan Becker