How to resolve "The type initializer for 'Gdip' threw an exception" for using ClosedXML in dotnet core webapi in Kubernates deployement?

Elaya Raja 96 Reputation points

I am using ClosedXml for my controller to return the excel file as response and it was working in windows local environment. I deployed the code in Kubernates and found the below exceptions in logs and not working. What was the solution to resolve this issue?

"Detail=The type initializer for 'Gdip' threw an exception.,
Exception=System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.\n --->
System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms.
See for more information.\n
at System.Drawing.LibraryResolver.EnsureRegistered()\n
at System.Drawing.SafeNativeMethods.Gdip.PlatformInitialize()\n
at System.Drawing.SafeNativeMethods.Gdip..cctor()\n --- End of inner exception stack trace ---\n
at System.Drawing.SafeNativeMethods.Gdip.GdipGetGenericFontFamilySansSerif(IntPtr& fontfamily)\n
at System.Drawing.FontFamily.GetGdipGenericSansSerif()\n
at System.Drawing.FontFamily.get_GenericSansSerif()\n
at System.Drawing.Font.CreateFont(String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte charSet, Boolean isVertical)\n
at System.Drawing.Font..ctor(String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)\n
at System.Drawing.Font..ctor(String familyName, Single emSize, FontStyle style)\n
at ClosedXML.Excel.FontBaseExtensions.GetCachedFont(IXLFontBase fontBase, Dictionary2 fontCache)\n at ClosedXML.Excel.FontBaseExtensions.GetWidth(IXLFontBase fontBase, String text, Dictionary2 fontCache)\n
at ClosedXML.Excel.XLColumn.AdjustToContents(Int32 startRow, Int32 endRow, Double minWidth, Double maxWidth)\n
at ClosedXML.Excel.XLColumn.AdjustToContents(Int32 startRow, Int32 endRow)\n
at ClosedXML.Excel.XLColumn.AdjustToContents(Int32 startRow)\n at ClosedXML.Excel.XLColumn.AdjustToContents()\n
at ClosedXML.Excel.XLColumns.<>c.<AdjustToContents>b__8_0(XLColumn c)\n
at System.Collections.Generic.List1.ForEach(Action1 action)\n
at ClosedXML.Excel.XLColumns.AdjustToContents()\n


A set of technologies in the .NET Framework for building web applications and XML web services.
2,599 questions
No comments
{count} votes

2 additional answers

Sort by: Most helpful
  1. Bruce ( 28,276 Reputation points

    the error is pretty clear. you must use a windows container, which requires a windows worker node or switch to a library that supports linux.

    windows containers in Kubernetes:

    No comments

  2. Elaya Raja 96 Reputation points

    Thanks for the update. Is there any open source available for creating Excel in dotnet core webapi with kubernates support?

    Thanks in advance.

    No comments