Search code examples
c#asp.net-corenugetskiasharp

Why does using SkiaSharp in a ASP.NET Core Web API cause a crash?


I am building an ASP.NET Core Web API project which will use SkiaSharp for rendering on the backend. The code works in a .NET Core desktop test application, but when we run the same code on the ASP.NET Core Web API project, the project crashes. The exception indicates it cannot find libSkiaSharp:

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

The .csproj is referencing SkiaSharp (and related Nuget packages) yet there must be some file that isn't making its way to the compiled folder. How can I solve this problem?


Solution

  • This problem is discussed in the following github issue:

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

    To solve the problem I had to do the following:

    1. Install the SkiaSharp.NativeAssets.Linux nuget package.
    2. Add the following to the dockerfile: RUN apt-get update && apt-get install -y libfontconfig1

    Note that after solving this problem I had an additional problem:

    Unable to load shared library 'libHarfBuzzSharp' or one of its dependencies

    To solve this, I installed HarfBuzzSharp.NativeAssets.Linux. I mention this in case anyone has the two errors like I did.