gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 00:32:34 25 4
gpt4 key购买 nike

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

[root@localhost TestLinux]# /usr/bin/mono ./Test.exe

我遇到了异常

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

输出清楚地表明 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>

如果有人过去偶然发现了这个,请告诉我。

最佳答案

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

关于c# - 在 CentOS 或 Linux 上使用 Mono 执行 .Net 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19588298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com