您现在的位置是:首页 > 文章详情

System.Drawing.Common在docker报错 The type initializer for 'Gdip' threw a...

日期:2019-05-23点击:1387

今天在asp.net core站点上做一个发送邮件附带二维码的功能,为了方便邮件接受者直接手机扫描打开特定h5页面。采用QRCoder,代码很简单几行

 QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(content, QRCodeGenerator.ECCLevel.Q); Base64QRCode qrCode = new Base64QRCode(qrCodeData); return qrCode.GetGraphic(5);

返回二维码的base64格式,嵌入img中显示,运行->测试,一切顺利。 提交代码,生成镜像更新到站点,同样的路径走一遍,发现收到的邮件中没有图片。检查日志发现

An unhandled exception has occurred while executing the request.
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()

github早有前人提交过同样的问题,解决方法是在生成镜像时安装缺失的包

 FROM microsoft/aspnetcore:2.0 AS base RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev

重新生成测试通过。
因为安装包的缘故,整个镜像生成时间将近20分钟,我就顺便做了一个包含安装包的基础镜像,这样方便后续更新

docker push wyxnj/aspnetcore:latest

用这个作为asp.net core runtime的基础镜像,可以和以前一样快速生成镜像并更新站点。

原文链接:https://yq.aliyun.com/articles/703578
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章