首页 新闻 会员 周边

asp.net core 2.1 容器中使用 System.Drawing.Common 的问题

1
悬赏园豆:30 [已解决问题] 解决于 2018-08-22 15:53

之前在 Ubuntu 16.04 上遇到过使用 System.Drawing.Common 的问题(博问链接),而这次是在 docker 容器中遇到了,报错信息与之前不一样,这次的错误是:

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()

容器镜像用的是 microsoft/dotnet:2.1-aspnetcore-runtime ,容器中已经安装了 libgdiplus

RUN apt-get update
RUN apt-get install -y libgdiplus
RUN cd /usr/lib && ln -s libgdiplus.so gdiplus.dll

请问如何解决?

dudu的主页 dudu | 高人七级 | 园豆:30979
提问于:2018-08-22 14:36
< >
分享
最佳答案
2

终于解决了!除了安装 libgdiplus 还要安装 libc6-dev,Dockerfile 如下

FROM microsoft/dotnet:2.1-aspnetcore-runtime
RUN apt-get update
RUN apt-get install -y --no-install-recommends libgdiplus libc6-dev 

为什么会找不到 libdl (libdl.so.2) 呢?是因为 System.Drawing.Common 是在 /usr/lib/x86_64-linux-gnu/ 这个路径中找的,而容器中 libdl.so.2 存在于 /lib/x86_64-linux-gnu/ 目录中,安装 libc6-dev 之后 /lib/x86_64-linux-gnu/ 中就有了 libdl.so.2 ,问题就解决了。

现在不需要 ln -s libgdiplus.so gdiplus.dll ,System.Drawing.Common 已经改了代码,直接加载 libgdiplus.so ,详见实现源码

解决方法是在 https://github.com/VahidN/EPPlus.Core/issues/40 的回复中发现的

dudu | 高人七级 |园豆:30979 | 2018-08-22 15:49
其他回答(2)
0

太高级了,看不懂,但是还是要占个坑,坐等楼下大神解答

DNLi | 园豆:316 (菜鸟二级) | 2018-08-22 15:29
1

在github上找的一个,不知道你有没有试过 https://github.com/VahidN/EPPlus.Core/issues/40#issuecomment-397182002

收获园豆:30
MrNice | 园豆:3450 (老鸟四级) | 2018-08-22 15:42

在看到你的回答之前就在这个issue中找到了解决方法

支持(0) 反对(0) dudu | 园豆:30979 (高人七级) | 2018-08-22 15:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册