'SkiaSharp.SKImageInfo' Exception in Aspose Word v18.8.0

I’m working in Aspose Word (v18.8.0) to convert Document to PDF. Code is working fine inside Visual Studio when i try to execute inside docker container using Linux ( Alpine) its throwing above exception

FROM mcr.microsoft.com/dotnet/core/sdk:3.0.100-alpine3.9 AS build-env
WORKDIR /usr/src/app
COPY . .
RUN dotnet publish ./test/test.csproj -c Release -o ./_publish
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0.0-alpine3.9

RUN apk update
RUN apk upgrade --available

RUN apk add libgdiplus --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted
RUN apk --no-cache add msttcorefonts-installer fontconfig freetype-dev libjpeg-turbo-dev libpng-dev && \
    update-ms-fonts && \
    fc-cache -f

RUN apk add Goelze.SkiaSharp.NativeAssets.AlpineLinux --version 1.68.0
RUN apk add --no-cache icu-libs
ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8

ENV ASPNETCORE_URLS http://+:5000
WORKDIR /app
COPY --from=build-env /usr/src/app/_publish ./
EXPOSE 5000/tcp
CMD ["dotnet", "test.dll"]

Error mess

Connection id "0HLRQ2FV5QQ5J", Request id "0HLRQ2FV5QQ5J:00000001": An unhandled exception was thrown by the application.

System.TypeInitializationException: The type initializer for   ' threw an exception.

 ---> System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.

 ---> System.DllNotFoundException: Unable to load shared library 'libSkiaSharp' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: Error loading shared library liblibSkiaSharp: No such file or directory

@pravnviji
Aspose.Words 18.8 used SkiaSharp 1.60.3 version. Goelze.SkiaSharp.NativeAssets.AlpineLinux required SkiaSharp 1.68.0 or newer. You should update to Aspose.Words 19.2.0 version (in this version 1.68.0 version of SkiaSharp is used). Or to the latest version, which uses 1.68.1 version of SkiaSharp.

You have to add Linux native assets for SkiaSharp to make it work in Linux Alpine. Add Nuget referenace to Goelze.SkiaSharp.NativeAssets.AlpineLinux. Also do not forget to install fontconfig in your container. It is required by SkiaSharp to work with fonts. Here is Dockerfile I used for testing Aspose.Words in Linux Alpine container.

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-alpine3.9 AS build
WORKDIR /app

# copy csproj and restore as distinct layers
COPY Aspose.Words.Docker.Sample/*.csproj ./Aspose.Words.Docker.Sample/
WORKDIR /app/Aspose.Words.Docker.Sample
RUN dotnet restore

# copy and publish app and libraries
WORKDIR /app/
COPY Aspose.Words.Docker.Sample/. ./Aspose.Words.Docker.Sample/
WORKDIR /app/Aspose.Words.Docker.Sample
RUN dotnet publish -c Release -o out

# copy to runtime environment
FROM mcr.microsoft.com/dotnet/core/runtime:2.2-alpine3.9 AS runtime
WORKDIR /app
# fontconfig is required to properly work with fonts in Linux.
RUN apk update && apk upgrade && apk add fontconfig
COPY --from=build /app/Aspose.Words.Docker.Sample/out ./
ENTRYPOINT ["dotnet", "Aspose.Words.Docker.Sample.dll"]

Note, Goelze.SkiaSharp.NativeAssets.AlpineLinux is compiled for Alpine Linux 3.9 and does not work on 3.8.

1 Like

Thank you its working right now