Unable to load shared library 'libSkiaSharp' in .net core 5.0 + linux

Hello Team,
I have an Azure Pipeline with my .Net Core 5.0 WebAPI project which is referenced the Nuget-Package Aspose.Words version 21.10.0, on my local win 10 OS it works fine. When we push our code to Higher environments starting with Dev, which is currently hosted using Azure in Linux throws an error when try to take advantage of Aspose.Words (attached exception screenshot).

I could able to print the word document before, but after code changes which I utilized Aspose.Words.Fields -it started giving the below error,

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

After findings so many topics like → here, here, here - I have tried these combinations to make my code works in the web-server, starting with (only with 1, with 2 & 3, with 2)

  1. Include=“SkiaSharp.NativeAssets.Linux” Version=“2.88.2”
  2. “SkiaSharp.NativeAssets.Linux.NoDependencies” Version=“2.88.2”
  3. “SkiaSharp” Version=“2.88.2”

other combinations like,

  1. “SkiaSharp” Version=“2.80.3”
  2. “SkiaSharp.NativeAssets.Linux.NoDependencies” Version=“2.80.3”

but still error occurs, request you to help me what could be wrong with the steps which I followed?

@sudi065 Which Linux distribution is used on your side? If possible could you please provide Dockerfile that emulate the problematic environment? Also, please attach your .csproj file here to check the references used in your project.
We will check the issue and provide you more information.

A post was split to a new topic: Unable to load libskiasharp .NET5

@alexey.noskov - We are using - alpine linux. I have attached the docker file image as reference as well as .csproj screenshot.
For now I’m just using “SkiaSharp” Version=“2.80.3” & “SkiaSharp.NativeAssets.Linux.NoDependencies” Version=“2.80.3” in order to find out any reason when I try to use the table of contents below code why it started throwing Unable to load shared library ‘libSkiaSharp’ error
// using Aspose.Words.Fields;
foreach (Field eachField in doc.Range.Fields.Where(x => x.Type == FieldType.FieldHyperlink))
{ if (eachField.Type == FieldType.FieldHyperlink && eachField.DisplayResult == “Table of contents”)
eachField.Remove(); }
docker.png (40.4 KB)
csprojectfile.png (62.8 KB)

@sudi065 I have investigated the issue and determined that there is a missed dependency of libSkiaSharp.so on Alpine Linux. Running the following command in the docker:

ldd libSkiaSharp.so

Returns the following:

    /lib/ld-musl-x86_64.so.1 (0x7ff838b7f000)
    libpthread.so.0 => /lib/ld-musl-x86_64.so.1 (0x7ff838b7f000)
    libdl.so.2 => /lib/ld-musl-x86_64.so.1 (0x7ff838b7f000)
    libm.so.6 => /lib/ld-musl-x86_64.so.1 (0x7ff838b7f000)
    libc.so.6 => /lib/ld-musl-x86_64.so.1 (0x7ff838b7f000)
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by libSkiaSharp.so)

As you can see the dependency ld-linux-x86-64.so.2 is missed. I have installed gcompat package to resolve this:

RUN apk add --no-cache gcompat

Here is my full Dockerfile:

FROM mcr.microsoft.com/dotnet/runtime:6.0-alpine3.15 AS base
WORKDIR /app

# Required to make SkiaSharp 2.80.1 work. If use 2.80.3 SkiaSharp.NativeAssets.Linux.NoDependencies it is not required.
#RUN apk add --no-cache fontconfig
# Requred to make code works on 6.0-alpine3.15. See https://docs.microsoft.com/en-us/answers/questions/728280/running-net-6-project-in-docker-throws-globalizati.html
RUN apk add --no-cache icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib
# For debug purposes.
RUN apk add --no-cache bash
# Add the missed ld-linux-x86-64.so.2 dependency.
RUN apk add --no-cache gcompat

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["TestNet6.csproj", "."]
RUN dotnet restore "./TestNet6.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "TestNet6.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "TestNet6.csproj" -c Release -r linux-x64 --no-self-contained -o /app/publish

FROM base AS final

WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestNet6.dll"] 

@alexey.noskov - Thank you very much, adding the below package resolved the issue in Docker file in --image builder section
RUN apk add --no-cache gcompat

in .csproj file the version which I used did not have any issues.

 <PackageReference Include="SkiaSharp" Version="2.80.3" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.3" />
1 Like