在CentOS或Linux上使用Mono执行.Net应用程序

Omk*_*kar 5 .net c# linux mono

我在Visual Studio 2010上使用C#.Net中的WinForm开发了一个测试应用程序.现在,我想在Linux下使用Mono在CentOS上运行它.所以我尝试了下面的命令序列 -

[root@localhost TestLinux]# /usr/bin/mono ./Test.exe
Run Code Online (Sandbox Code Playgroud)

我遇到了一个例外

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] 
Run Code Online (Sandbox Code Playgroud)

在做一些研究的时候,我发现这是由于gdiplus.dll与其对应部分libgdiplus.so.0在linux上的链接,需要将其条目放在ldconfig缓存中.

[root@localhost TestLinux]# ldconfig -p | grep libgdiplus
    libgdiplus.so.0 (libc6) => /usr/lib/libgdiplus.so.0
Run Code Online (Sandbox Code Playgroud)

输出清楚地显示libgdiplus.so.0在ldconfig缓存中,但程序仍然无法正常工作.我还尝试在应用程序配置中添加DllMap条目,如下所示

<?xml version="1.0"?>
<configuration>
<startup>
  <supportedRuntime version="v2.0.50727"/>
</startup>  
    <dllmap dll="gdiplus.dll" target="libgdiplus.so.0"/>  
</configuration>
Run Code Online (Sandbox Code Playgroud)

如果有人在过去偶然发现这件事,请告诉我.

icb*_*tes 3

您已经错误地追踪了错误。您的单声道版本不支持 EnableVisualStyles。升级到支持它的版本(据我记得它是 >= 2.9 )或尝试在您的 .net 应用程序中禁用此功能,这将导致“不太好的 ui 元素”。对我来说它很有效,因为我正在 gentoo 上工作。突然,在出现之后,我的单声道应用程序不再崩溃了。