mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.51k stars 537 forks source link

"The type initializer for 'SkiaSharp.SKAbstractManagedWStream' threw an exception." occuring if QuestPDF library published in Docker container. #2096

Closed 71a1den closed 2 years ago

71a1den commented 2 years ago

Hello. I am trying to use the QuestPDF library with docker container. If i try to send a request via Postman, the following exception was occured:

"The type initializer for 'SkiaSharp.SKAbstractManagedWStream' threw an exception."


Dockerfile FROM mcr.microsoft.com/dotnet/sdk:6.0-focal as build WORKDIR /src RUN apt-get update && apt-get install libfontconfig1 -y COPY . .

RUN dotnet restore "./DataExportService.csproj" RUN dotnet publish "./DataExportService.csproj" -c Release -o /app --no-restore

FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal WORKDIR /app COPY --from=build /app ./ EXPOSE 5000

ENTRYPOINT ["dotnet", "DataExportService.dll"]


Is it possible to suppress this error and make the container work correctly? Thanks.

image
71a1den commented 2 years ago

Hello again. I managed to solve the problem myself. Below you will find the updated Dockerfile.

FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal AS base
WORKDIR /app
RUN apt-get update && apt-get install -y ttf-mscorefonts-installer fontconfig libc6 libc6-dev libgtk2.0-0 libnss3 libatk-bridge2.0-0 libx11-xcb1 libxcb-dri3-0 libdrm-common libgbm1 libasound2 libappindicator3-1 libxrender1 libfontconfig1 libxshmfence1
RUN chmod 777 .

FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS build
WORKDIR /src
COPY ["DataExportService.csproj", "DataExportService/"]
RUN dotnet restore "DataExportService/DataExportService.csproj"

WORKDIR "/src/DataExportService"
COPY . .
RUN dotnet build "DataExportService.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "DataExportService.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DataExportService.dll"]

Additional info: Also you need to specify a supported font in the document page.DefaultTextStyle(x => x.FontFamily(Fonts.Arial));