[Linux] Aspose.PDF Stamping Error — Unable to Load libSkiaSharp (Dependency Issue on EC2 Linux)

Hi Aspose Support Team,

I encountered the following error while stamping a PDF document using Aspose.PDF in a .NET Core 3.1 application running on Amazon EC2 (Linux).
The same code and configuration work perfectly on Windows, but fail on Linux due to a libSkiaSharp loading issue.
I have also included the required fonts within the project folder itself.


Error Log

Unhandled exception. System.TypeInitializationException: The type initializer for ...
---> System.DllNotFoundException: Unable to load shared library 'libSkiaSharp' ...
   at SkiaSharp.SkiaApi.sk_version_get_milestone()
   at SkiaSharp.SkiaSharpVersion.get_Native()
   at SkiaSharp.SkiaSharpVersion.CheckNativeLibraryCompatible(Boolean throwIfIncompatible)
   at SkiaSharp.SKObject..cctor()
--- End of inner exception stack trace ---
   at SkiaSharp.SKObject.DeregisterHandle(IntPtr handle, SKObject instance)
   at SkiaSharp.SKObject.set_Handle(IntPtr value)

Systemd reported:

xxxxx.service: main process exited, code=killed, status=6/ABRT
xxxxx.service entered failed state.

Environment Details

  • .NET Core: 3.1
  • OS: Amazon EC2 Linux (x86_64)
  • Aspose.PDF: 21.6.0
  • SkiaSharp: 2.88.6
  • SkiaSharp.NativeAssets.Linux: 2.88.6
  • Status: Works fine on Windows, issue only in Linux

Project File Snippet

<ItemGroup>
  <Content Include="ProductionServicev2\Fonts\**\*.*">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </Content>
</ItemGroup>

<ItemGroup>
  <PackageReference Include="Magick.NET-Q16-AnyCPU" Version="14.9.0" />
  <PackageReference Include="PdfSharp.Core" Version="1.0.0" />
  <PackageReference Include="PdfiumViewer" Version="2.13.0" />
  <PackageReference Include="AWSSDK.Textract" Version="3.7.501.4" />
  <PackageReference Include="Aspose.PDF" Version="21.6.0" />
  <PackageReference Include="SkiaSharp" Version="2.88.6" />
  <PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
</ItemGroup>

Troubleshooting Performed

I verified that libSkiaSharp.so exists under multiple runtime paths:

/home/ec2-user/app/api/runtimes/linux-x64/native/libSkiaSharp.so
/home/ec2-user/app/wfserver/runtimes/linux-x64/native/libSkiaSharp.so

Then I checked its dependencies:

ldd /home/ec2-user/app/wfserver/runtimes/linux-x64/native/libSkiaSharp.so
libfontconfig.so.1 => not found

After installing the missing dependencies:

sudo yum install -y fontconfig freetype libpng libjpeg-turbo expat libX11 libxcb libXext libXrender

All dependencies resolved successfully, and the PDF stamping started working fine after a server restart.


Question

Since the same setup works fine on Windows but fails on Linux until dependencies are manually installed,
is there a recommended way to bundle or include these required native dependencies (like libfontconfig, libfreetype, etc.)
programmatically or during deployment — so that manual installation via yum on the Linux server isn’t required?

Any suggestions to make the Aspose.PDF + SkiaSharp setup fully self-contained for Linux environments would be greatly appreciated.

@ragu2736

To bundle or include the required native dependencies like libfontconfig, libfreetype, etc., programmatically or during deployment on Linux, consider the following approaches:

  1. Use a Docker Container: Create a Docker image that includes all the necessary dependencies. This ensures that your application runs in a consistent environment regardless of the underlying system. Here’s a basic example of a Dockerfile:

    FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
    WORKDIR /app
    COPY . .
    RUN apt-get update && apt-get install -y \
        fontconfig \
        freetype \
        libpng \
        libjpeg-turbo \
        && rm -rf /var/lib/apt/lists/*
    ENTRYPOINT ["dotnet", "YourApp.dll"]
    
  2. Include Native Libraries in Your Project: You can include the native libraries directly in your project and configure them to be copied to the output directory. This requires manual management of the libraries and ensuring compatibility with the target environment.

  3. Use a Package Manager: For deployments across multiple servers, consider using a configuration management tool (such as Ansible, Chef, or Puppet) to automate the installation of these dependencies during the deployment process.

  4. Create a Shell Script: Write a shell script that installs the required dependencies and execute it as part of your deployment process. This script can be run after your application is deployed.

By utilizing one of these methods, you can streamline the installation of dependencies on each server and create a more self-contained setup for your Aspose.PDF + SkiaSharp application in Linux environments.

If you have further questions or need assistance with a specific approach, feel free to ask!

I am now going to use SkiaSharp.NativeAssets.Linux.NoDependencies , Version="2.88.6"as I have Fonts folder in my project.