Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing .Net Application using Mono on CentOS or Linux

Tags:

c#

.net

linux

mono

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.

like image 576
Omkar Avatar asked Oct 02 '22 14:10

Omkar


1 Answers

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.

like image 131
icbytes Avatar answered Oct 13 '22 12:10

icbytes