Executing .Net Application using Mono on CentOS or Linux
I have develop a Test Application using WinForm in C# .Net on Visual Studio 2010. Now, I want to run this under Linux using Mono on CentOS. So I tried below command sequence -
[root@localhost TestLinux]# /usr/bin/mono ./Test.exe
I hit an exception
Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.DllNotFoundException: gdiplus.dll
at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
at System.Drawing.GDIPlus..cctor () [0x00000] --- End of inner exception stack trace ---
at <0x00000> <unknown method>
at System.Drawing.Graphics.FromHdcInternal (IntPtr hdc) [0x00000]
at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000]
at System.Windows.Forms.XplatUIX11..ctor () [0x00000]
at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000]
at System.Windows.Forms.XplatUI..cctor () [0x00000] --- End of inner exception stack trace ---
at <0x00000> <unknown method>
at System.Windows.Forms.Application.EnableVisualStyles () [0x00000]
at Test.Program.Main () [0x00000]
While doing some research I found that this is due to linking between gdiplus.dll and its counter part libgdiplus.so.0 on linux, need to put its entry in ldconfig cache.
[root@localhost TestLinux]# ldconfig -p | grep libgdiplus
libgdiplus.so.0 (libc6) => /usr/lib/libgdiplus.so.0
The output clearly shows that libgdiplus.so.0 is there in ldconfig cache but still the program is not working. I also tried to add DllMap entry in application configuration as below
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
<dllmap dll="gdiplus.dll" target="libgdiplus.so.0"/>
</configuration>
Please let me know if anybody stumbled upon this in past.
You have traced the error wrong. Your mono version does not support EnableVisualStyles. Upgrade to a version, which supports it ( as far as i remember it is >= 2.9 ) or try to disable this feature in Your .net application, which will result in "not so nice ui elements". For me it worked, as i was working on gentoo. Suddenly, after a emerge, my mono application did not crash anymore.
Also be sure that libgdiplus.so.0 is actually installed and on the path, it is not by default in mono. But yes, the main thing is CentOS comes with an outdated version of mono by default.
链接地址: http://www.djcxy.com/p/90060.html上一篇: Windows上的Mono有什么意义?