首页 新闻 赞助 找找看

.Net Core 使用 System.Drawing.Common 在CentOS下报错

0
[已解决问题] 解决于 2018-07-14 19:09

.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下要另外安装什么吗?怎么安装?

大豆男生的主页 大豆男生 | 小虾三级 | 园豆:608
提问于:2018-07-14 16:27
< >
分享
最佳答案
0

看一下 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
奖励园豆:5
dudu | 高人七级 |园豆:31075 | 2018-07-14 17:03

我们是在 ubuntu 上使用的 System.Drawing.Common ,当时遇到的问题是 .NET Core使用System.Drawing.Common时找不到libgdiplus的问题

dudu | 园豆:31075 (高人七级) | 2018-07-14 17:04

謝謝,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了

 

 

 

大豆男生 | 园豆:608 (小虾三级) | 2018-07-14 19:08
其他回答(4)
0

同样遇到这个问题,感谢题主

李0539 | 园豆:442 (菜鸟二级) | 2019-02-28 17:03
0

非常感谢您

剑仙也风流 | 园豆:174 (初学一级) | 2020-09-21 09:50
0

我还是没有解决,按照上面的方法

何少-_- | 园豆:202 (菜鸟二级) | 2021-07-23 21:42
0

同求,我的也是遇到这个问题,在Centos8里面解决不了。。。哭了

码农初养成 | 园豆:202 (菜鸟二级) | 2021-11-25 16:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册