網頁

Windows Container之.NET Core找不到gdiplus.dll解決方案

Windows Container之.NET Core找不到gdiplus.dll解決方案

同事回報,有一支 API 轉移至 Windows Container 之後,特定 Action 會產生 HTTP 500 錯誤,查詢容器日誌快速定位到問題:

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HLHTEASOTJDP", Request id "0HLHTEASOTJDP:00000002": An unhandled exception was thrown by the application.
System.TypeInitializationException: The type initializer for 'ClosedXML.Excel.XLHelper' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Gdip' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'gdiplus.dll': The specified module could not be found.
   at System.Runtime.InteropServices.FunctionWrapper`1.get_Delegate()
   at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
   at System.Drawing.SafeNativeMethods.Gdip..cctor()
   --- End of inner exception stack trace ---
   at System.Drawing.SafeNativeMethods.Gdip.GdipCreateBitmapFromScan0(Int32 width, Int32 height, Int32 stride, Int32 format, HandleRef scan0, IntPtr& bitmap)
   at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
   at ClosedXML.Excel.XLHelper..cctor()
   --- End of inner exception stack trace ---