簡體   English   中英

在CentOS或Linux上使用Mono執行.Net應用程序

[英]Executing .Net Application using Mono on CentOS or Linux

我在Visual Studio 2010上使用C#.Net中的WinForm開發了一個測試應用程序。現在,我想在Linux下使用Mono在CentOS上運行它。 所以我嘗試了下面的命令序列 -

[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與其對應部分libgdiplus.so.0在linux上的鏈接,需要將其條目放在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。 突然,在出現之后,我的單聲道應用程序不再崩潰了。

還要確保libgdiplus.so.0實際安裝並且在路徑上,默認情況下不是單聲道。 但是,是的,主要的是CentOS默認配備了過時的單聲道版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM