我已经在Visual Studio 2010的C#.Net中使用WinForm开发了一个测试应用程序。现在,我想在CentOS上使用Mono的Linux下运行该应用程序。所以我尝试了以下命令序列-
[root@localhost TestLinux]# /usr/bin/mono ./Test.exe
我碰到一个异常(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]
在进行一些研究时,我发现这是由于gdiplus.dll与Linux的对应部分libgdiplus.so.0之间的链接所致,需要将其条目放入ldconfig缓存中。
[root@localhost TestLinux]# ldconfig -p | grep libgdiplus
libgdiplus.so.0 (libc6) => /usr/lib/libgdiplus.so.0
输出清楚地表明ldconfig缓存中存在libgdiplus.so.0,但该程序仍无法正常工作。我还尝试在应用程序配置中添加DllMap条目,如下所示
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
<dllmap dll="gdiplus.dll" target="libgdiplus.so.0"/>
</configuration>
如果有人过去偶然发现此消息,请告诉我。
最佳答案
您已将错误跟踪为错误。
您的单声道版本不支持EnableVisualStyles。
升级到支持它的版本(据我所知,它是> = 2.9)或尝试在.net应用程序中禁用此功能,这将导致“不太好的ui元素”。
对我来说,就像我在gentoo上工作一样,它起作用了。
突然,出现之后,我的单声道应用程序不再崩溃。
关于c# - 在CentOS或Linux上使用Mono执行.Net应用程序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19588298/