Tôi đã phát triển một ứng dụng thử nghiệm bằng WinForm trong C# .Net trên Visual Studio 2010. Bây giờ, tôi muốn chạy điều này dưới Linux sử dụng Mono trên CentOS. Vì vậy, tôi đã cố gắng bên dưới dãy lệnh -Thực thi .Net Ứng dụng sử dụng Mono trên CentOS hoặc Linux
[[email protected] TestLinux]# /usr/bin/mono ./Test.exe
tôi nhấn một ngoại lệ
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]
Trong khi làm một số nghiên cứu tôi thấy rằng điều này là do liên kết giữa gdiplus.dll và truy cập phần libgdiplus.so.0 của nó trên linux, cần phải đặt mục nhập của nó trong bộ nhớ cache ldconfig.
[[email protected] TestLinux]# ldconfig -p | grep libgdiplus
libgdiplus.so.0 (libc6) => /usr/lib/libgdiplus.so.0
Kết quả hiển thị rõ ràng rằng libgdiplus.so.0 có trong bộ nhớ cache ldconfig nhưng chương trình vẫn không hoạt động. Tôi cũng đã cố thêm mục nhập DllMap vào cấu hình ứng dụng như bên dưới
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
<dllmap dll="gdiplus.dll" target="libgdiplus.so.0"/>
</configuration>
Hãy cho tôi biết nếu có ai vấp phải điều này trong quá khứ.
Tại sao bạn sử dụng WinForm? WinForm is't hoàn toàn được thực hiện trong mono. Ngoài ra GTK # ứng dụng trông tự nhiên hơn trên Linux. – Deffiss