Unable to load libskiasharp .NET5

I have just faced the same issue after I added Aspose.Words v22.9.0 as the dependency to my .NET 5.0 project. I’m running the project in the Docker container. Here is my Dockerfile for the reference:

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
LABEL stage=builder

WORKDIR /solution
COPY . .

WORKDIR /solution/src/project

RUN --mount=type=cache,target=/root/.nuget dotnet publish "Project.csproj" -c Release -o /app/publish

FROM mcr.microsoft.com/dotnet/aspnet:5.0
RUN apt-get update && apt-get install -y libfontconfig1
WORKDIR /app
COPY --from=build /app/publish .

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

Here are the exception details:

System.TypeInitializationException: The type initializer for 'Fo' 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: liblibSkiaSharp: cannot open shared object file: No such file or directory
   at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
   at SkiaSharp.SKImageInfo..cctor()
   --- End of inner exception stack trace ---
   at SkiaSharp.SKBitmap..ctor(Int32 width, Int32 height, Boolean isOpaque)
   at Fo..cctor()
   --- End of inner exception stack trace ---
   at Fo..ctor(Byte[] a)
   at YZa.v()
   at YZa.q(Boolean a, Boolean b, q7 c)
   at e0a.u(Shape a)
   at e0a.t(Shape a)
   at e0a.r(Shape a)
   at e0a.h(ShapeBase a)
   at e0a.e(ShapeBase a)
   at l0a.VisitShapeStart(Shape a)
   at Aspose.Words.Drawing.Shape.r3ka8zscesabkstb24kjjv9sml9wq7pwMiB(DocumentVisitor a)
   at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
   at Aspose.Words.Drawing.Shape.Accept(DocumentVisitor visitor)
   at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
   at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
   at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
   at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
   at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
   at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
   at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
   at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
   at l0a.l0aMiB(w4a a)
   at bpa.bpaMib(w4a a)
   at Aspose.Words.Document.Ya(w4a a)
   at Aspose.Words.Document.La(Stream a, String b, SaveOptions c)

@alexeydefinely Aspose.Words for .NET Standard uses SkiaSharp to deal with graphics, to make it work on Linux you have to add reference either to SkiaSharp.NativeAssets.Linux or to SkiaSharp.NativeAssets.Linux.NoDependencies

If you add reference to SkiaSharp.NativeAssets.Linux, you should also install libfontconfig1 in your system. SkiaSharp.NativeAssets.Linux depends on this library. You can use the following command to install it:

apt-get update && apt-get install -y libfontconfig1

If you do not have rights to install packages, or other reasons not to install libfontconfig1, you can simply use SkiaSharp.NativeAssets.Linux.NoDependencies, which does not require installation of libfontconfig1.

references in you .csproj should look like this

<PackageReference Include="Aspose.Words" Version="22.9.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.3" />

or like this:

<PackageReference Include="Aspose.Words" Version="22.9.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.3" />
1 Like

Thank you, after I added the dependency to SkiaShart.NativeAssets.Linux package the issue has been solved.

1 Like