【问题标题】:Can't run WinForms Mono application on CentOS 7无法在 CentOS 7 上运行 WinForms Mono 应用程序
【发布时间】:2025-12-17 14:25:02
【问题描述】:

我已经在我的 CentOS 7 上安装了 Mono (4.2.3) 和 libgdiplus (4.2),并且安装似乎一切正常。 mono-test-install 返回:

Active Mono: /opt/mono/bin/mono
Your have a working System.Drawing setup
Your file system watcher is: System.IO.InotifyWatcher

还编译和启动控制台 HelloWorld 应用程序没有问题,但无法运行任何 winforms 应用程序(包括来自 Mono 网站的最简单的 HelloWorld 示例)。它在尝试运行时给了我以下消息:

Unhandled Exception: System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter] 
    at System.Drawing.GDIPlus.CheckStatus (Status status) <0x419aac90 + 0x0015f> in :0 
    at System.Drawing.Bitmap..ctor (Int32 width, Int32 height, PixelForm
    at format) <0x419fe280 + 0x00053> in :0 
    at System.Drawing.Bitmap..ctor (System.Drawing.Image original, Int32 width, Int32 height) <0x41a004a0 + 0x0002f> in :0 
    at System.Drawing.Bitmap..ctor (System.Drawing.Image original, Size newSize) <0x41a00460 + 0x0002b> in :0 
    at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:.ctor (System.Drawing.Image,System.Drawing.Size) 
    at System.Windows.Forms.XplatUIX11.DefineCursor (System.Drawing.Bitmap bitmap, System.Drawing.Bitmap mask, Color cursor_pixel, Color mask_pixel, Int32 xHotSpot, Int32 yHotSpot) <0x419ffaf0 + 0x0020b> in :0 
    at System.Windows.Forms.XplatUI.DefineCursor (System.Drawing.Bitmap bitmap, System.Drawing.Bitmap mask, Color cursor_pixel, Color mask_pixel, Int32 xHotSpot, Int32 yHotSpot) <0x419ffa70 + 0x00070> in :0 
    at System.Windows.Forms.Cursor.CreateCursor (System.IO.Stream stream) <0x419fc0e0 + 0x00193> in :0 
    at System.Windows.Forms.Cursor..ctor (System.Type type, System.String resource) <0x419fbea0 + 0x0006b> in :0 
    at System.Windows.Forms.Cursors.get_SizeNWSE () <0x419fbd40 + 0x0005b> in :0 
    at System.Windows.Forms.SizeGrip..ctor (System.Windows.Forms.Control CapturedControl) <0x419fbcb0 + 0x0001f> in :0 
    at (wrapper remoting-invoke-with-check) System.Windows.Forms.SizeGrip:.ctor (System.Windows.Forms.Control) 
    at System.Windows.Forms.ScrollableControl.CreateScrollbars () <0x419f8e40 + 0x004ff> in :0 
    at System.Windows.Forms.ScrollableControl..ctor () <0x419a5e30 + 0x00387> in :0 
    at System.Windows.Forms.ContainerControl..ctor () <0x419a5ca0 + 0x00027> in :0 
    at System.Windows.Forms.Form..ctor () <0x419a5420 + 0x000bb> in :0 
    at HelloWorld..ctor () <0x419a2fa0 + 0x0000f> in :0 
    at (wrapper remoting-invoke-with-check) HelloWorld:.ctor () 
    at HelloWorld.Main () <0x419a2d90 + 0x0001f> in :0 

试过也运行 MONO_LOG_LEVEL="debug" MONO_LOG_MASK="dll" mono test.exe

它会找到所有需要的库。在互联网上发现很少有类似的消息,但在任何地方都没有解决方案。努力使用我的大脑,但仍然一无所获。不久前,我在同一系统中安装了相同版本的 Mono,但在另一台机器上运行得很好。无论我是通过 yum 安装还是从源代码编译,都会显示此消息。

【问题讨论】:

  • 看来你自己安装了mono,从源代码编译(因为/opt前缀),这大部分时间是错误的,你只想在这个前缀中安装安装第二个并行版本的单声道(除了您的发行版提供的版本)。最重要的是,我的经验是 RedHat 家族的发行版(Fedora、CentOS)以非常不稳定的方式与 mono 一起工作。我建议您首先使用发行版提供的软件包尝试 Ubuntu16.04,首先排除您的问题来自您选择此发行版的可能性。

标签: c# .net linux mono centos


【解决方案1】:

这似乎是 System.Drawing DLL 的问题,类似于 another answer I wrote

首先,找到 System.Drawing.dll 文件所在的目录(例如 /opt/mono-4.4.0/lib/gac/System.Drawing/4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll)

在名为System.Drawing.dll.config 的同一目录中创建一个文件,内容如下,将目录更新到libgdiplus.so 的正确位置:

<configuration>
  <dllmap dll="gdiplus.dll" target="/opt/mono-4.4.0/lib/libgdiplus.so"/>
</configuration>

【讨论】:

  • 这并没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方发表评论 - 您可以随时对自己的帖子发表评论,一旦您获得足够的声誉,您就可以对任何帖子发表评论。如果您有一个相关但不同的问题,请提出一个引用该问题的新问题,如果它有助于提供上下文。
最近更新 更多