.Net Core控制台项目,添加了 System.Drawing.Common 引用
using System; using System.IO; using System.Drawing; namespace imagetest1 { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); byte[] bytes = File.ReadAllBytes("bd_logo1.png"); using (MemoryStream ms = new MemoryStream(bytes)) { Image img = Image.FromStream(ms); Console.WriteLine($"{img.Width},{img.Height}"); } Console.Read(); } } }
在CentOS下报错:
Unhandled Exception: System.TypeInitializationException: The type initializer for 'Gdip' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'libdl' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl: cannot open shared object file: No such file or directory at Interop.Libdl.dlopen(String fileName, Int32 flag) at System.Drawing.SafeNativeMethods.Gdip.LoadNativeLibrary() at System.Drawing.SafeNativeMethods.Gdip..cctor() --- End of inner exception stack trace --- at System.Drawing.SafeNativeMethods.Gdip.GdipLoadImageFromDelegate_linux(StreamGetHeaderDelegate getHeader, StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, StreamCloseDelegate close, StreamSizeDelegate size, IntPtr& image) at System.Drawing.Image.InitFromStream(Stream stream) at System.Drawing.Image.LoadFromStream(Stream stream, Boolean keepAlive) at imagetest1.Program.Main(String[] args) in F:\imagetest1\imagetest1\Program.cs:line 13
CentOS下要另外安装什么吗?怎么安装?
看一下 centos 上的 libdl 版本是多少?
# ls /usr/lib/libdl*
/usr/lib/libdl-2.17.so /usr/lib/libdl.so.2
然后创建软链接试试
# ln -s libdl-2.xxx.so libdl.so
我们是在 ubuntu 上使用的 System.Drawing.Common ,当时遇到的问题是 .NET Core使用System.Drawing.Common时找不到libgdiplus的问题
謝謝,CentOS里是这样解决的:
#locate libdl /usr/lib64/libdl-2.17.so /usr/lib64/libdl.so.2 #cd /usr/lib64 #ln -s libdl-2.17.so libdl.so
然后又报另外一个错误:Unable to load DLL 'libgdiplus'
yum install libgdiplus-devel
这样就OK了
同样遇到这个问题,感谢题主
非常感谢您
我还是没有解决,按照上面的方法
同求,我的也是遇到这个问题,在Centos8里面解决不了。。。哭了