Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

510
Views
System.drawing.common el inicializador de tipo para 'gdip' lanzó una excepción

Este es mi código para agregar una imagen a una hoja de trabajo. Obtengo la imagen como un byte de la base de datos. La versión de .Net Core framework es 2.2.104. Este es un proyecto API. En mi localidad, el código funciona bien. Uso la versión 0.95.4 del componente ClosedXML como se muestra a continuación.

 [HttpPost("GetTowel")] public IActionResult GetTowel() { string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; string fileName = "Towel Quotation.xlsx"; try { using (var workbook = new XLWorkbook()) { IXLWorksheet worksheet = workbook.Worksheets.Add("Towel Quotation"); 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("P1")).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("",ex.Message)); } }

marcos

La información de mi servidor Kubernetes está a continuación:

 System.drawing.common the type initializer for 'gdip' threw an exception
 *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="http://+" ENV ASPNETCORE_Kestrel__Certificates__Default__Password="*****" WORKDIR /app COPY --from=build /app/temp/out ./ ENTRYPOINT ["dotnet", "blahblah.dll"]*

En el lado del servidor, obtengo la excepción de la siguiente manera: "system.drawing.common, el inicializador de tipo para 'gdip' lanzó una excepción"

He buscado muchas veces en google. De esa manera, generalmente se sugiere agregar un archivo docker:

 RUN apt-get install libgdiplus

Pero de esta manera tampoco resolvió mi problema. Alguien puede ayudarme?

Gracias por adelantado.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Tengo un Dockerfile como este:

 FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev WORKDIR /app EXPOSE 80 EXPOSE 443 FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build WORKDIR /src COPY ...

Estoy ejecutando el comando apt-get update and install en la segunda línea. Puede ejecutar su comando de esta manera. Espero que funcione para ti tambien.

over 4 years ago · Santiago Trujillo Report

0

La respuesta más aceptada no funcionó para mí en ubuntu 20.04 y parece que se eliminó la compatibilidad con sistemas operativos que no son de Windows para .NET 6:

System.Drawing.Common solo se admite en Windows

Las alternativas sugeridas son:

Para usar estas API para aplicaciones multiplataforma, migre a una de las siguientes bibliotecas:

ImageSharp https://github.com/SixLabors/ImageSharp

SkiaSharp https://github.com/mono/SkiaSharp

Microsoft.Maui.Graphics https://github.com/dotnet/Microsoft.Maui.Graphics

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!