<p>This is my code to add a picture to a worksheet. I get the picture as a byte from the database. .Net Core framework version is 2.2.104. This is an API project. In my locale, the code works well. I use the ClosedXML component 0.95.4 version as below.</p>
<pre><code>[HttpPost(&quot;GetTowel&quot;)]
public IActionResult GetTowel()
{
    string contentType = &quot;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet&quot;;
    string fileName = &quot;Towel Quotation.xlsx&quot;;
    try
    {
        using (var workbook = new XLWorkbook())
        {
            IXLWorksheet worksheet = workbook.Worksheets.Add(&quot;Towel Quotation&quot;);
            
            byte[] bytes = _fileService.Get(159).FileInBytes;
            System.IO.Stream x = new System.IO.MemoryStream(bytes);

            //the exception is throwed at this line:
            **var image = worksheet.AddPicture(x).MoveTo(worksheet.Cell(&quot;P1&quot;)).Scale(1.0);**

            using (var stream = new MemoryStream())
            {
                workbook.SaveAs(stream);
                var content = stream.ToArray();
                return File(content, contentType, fileName);
            }
        }
    }
    catch (Exception ex)
    {
        return BadRequest(ErrorResultFormatter.PrepareErrorResult(&quot;&quot;,ex.Message));
    }
}
</code></pre>
<p><a href="https://i.stack.imgur.com/lF8r8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/lF8r8.png" alt="frameworks" /></a></p>
<p>My Kubernetes server information is below:</p>
<pre><code>System.drawing.common the type initializer for 'gdip' threw an exception
</code></pre>
<pre><code>*FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build WORKDIR /app
COPY *.csproj Nuget.Config ./ RUN dotnet restore /property:Configuration=Release
--configfile=Nuget.Config --no-cache --force
COPY . ./temp/ WORKDIR /app/temp RUN dotnet publish -c Release -o out FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime ENV ASPNETCORE_URLS=&quot;http://+&quot; ENV ASPNETCORE_Kestrel__Certificates__Default__Password=&quot;*****&quot; WORKDIR /app COPY --from=build /app/temp/out ./ ENTRYPOINT [&quot;dotnet&quot;, &quot;blahblah.dll&quot;]*
</code></pre>
<p>On the server-side, I get the exception as below: &quot;system.drawing.common the type initializer for 'gdip' threw an exception&quot;</p>
<p>I have searched many times on google. That way is suggested generally to add docker file:</p>
<pre><code>RUN apt-get install libgdiplus
</code></pre>
<p>But this way also didn't solve my problem. Can anybody help me?</p>
<p>Thanks in advance.</p>

<p>I have a Dockerfile like this:</p>
<pre><code>FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
RUN apt-get update &amp;&amp; apt-get install -y apt-utils libgdiplus libc6-dev
        
WORKDIR /app
EXPOSE 80
EXPOSE 443
        
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ...
    
.
.
.
    
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT [&quot;dotnet&quot;, &quot;...dll&quot;]
</code></pre>
<p>I am running <code>apt-get update and install</code> command on the second line. You may run your command like this. I hope it works for you too.</p>
