简体   繁体   中英

Can't run WinForms Mono application on CentOS 7

I have installed Mono (4.2.3) and libgdiplus (4.2) on my CentOS 7 and everything seems to be fine with the installation. mono-test-install returns:

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

Also compiled and launched console HelloWorld application without issues, but can't run any winforms app (including simplest HelloWorld example from Mono website). It gives me following messages when trying to run:

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 

Tried also run with MONO_LOG_LEVEL="debug" MONO_LOG_MASK="dll" mono test.exe

and it finds all the libraries needed. Found few similar messages in the Internet but no solutions anywhere. Tried hard to use my brain and still nothing. A while ago I have installed the same version of Mono in the same system but other machine and it worked just fine. This message shows up no matter if I install via yum or compiling from sources.

This seems like a problem with the System.Drawing DLL, similar to another answer I wrote .

First, locate the directory where is the System.Drawing.dll file (for example /opt/mono-4.4.0/lib/gac/System.Drawing/4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll )

Create a file in the same directory called System.Drawing.dll.config with the following content, updating the directory to the correct location of libgdiplus.so :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM