.net core 2.2, new Bitmap出错 The type initializer for 'Gdip' threw an exception


.net core 2.2以下,目前3.0正式版还没发布,不知3.0有没有此问题

Image image = new Bitmap(400, 200);

new的时候会报错:The type initializer for 'Gdip' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'libdl' or one of its dependencies

关于此问题,这位老哥有详细的描述

我的解决办法:

在Dockerfile文件中加上,然后运行,编译。

RUN ln -s /lib/x86_64-linux-gnu/libdl-2.24.so /lib/x86_64-linux-gnu/libdl.so
RUN apt-get update
RUN apt-get install libgdiplus -y && apt-get clean && ln -s libgdiplus.so gdiplus.dll

延伸学习:

libdl.so

作用:在程序运行时找到指定的so并连接
有4个函数:
dlopen//打开一个动态库
dlsym//在打开的动态库里找一个函数
dlclose//关闭动态库
dlerror//返回错误

libgdiplus.so
libgdiplus是一个Mono库,用于对非Windows操作系统提供GDI+兼容的API。
libgdiplus是mono中的System.Drawing依赖的一个组件,用于显示web页面基本颜色等。
具体可以看 http://www.mono-project.com/Libgdiplus 

关于Mono Libgdiplus库,善友大哥的文章有介绍:

如有疑问,欢迎留言交流。