1. 程式人生 > 其它 >Linux環境下 ,匯出檔案功能報錯“The type initializer for 'Gdip' threw an exception”

Linux環境下 ,匯出檔案功能報錯“The type initializer for 'Gdip' threw an exception”

asp .net core 專案 部署在docker中,檔案匯出使用了System.Drawing.Common包,在容器中使用時報錯“The type initializer for 'Gdip' threw an exception.” 排查了一下,發現是docker容器中   System.Drawing.Common Gdiplus 相關依賴缺失的緣故

解決方案:

1.遠端連線伺服器

2.輸入指令

1、apt-get install libgdiplus
2、cd /usr/lib
3、ln -s libgdiplus.so gdiplus.dll   或 sudo ln -s libgdiplus.so gdiplus.dll

3.修改dockerfile檔案,加上以下兩句程式碼

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

4.修改成功後重新發布,就不會再報錯了。但是有了新的錯誤

解決:配置檔案修改了一下,將檔案儲存的目錄進行掛載以後就能成功匯出檔案了

 

注意:除此之外還有需要注意的地方就是檔案的路徑問題,linux和windows的寫法不同,路徑帶有中文和“/”也會有問題,需要處理