SkiaSharp exception

Hi

While performing doc to pdf conversion I am getting the below skiasharp exception.

Exception: System.TypeInitializationException: The type initializer for ‘yY’ 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 using a tool like strace. If you’re using glibc, consider setting the LD_DEBUG environment variable:
/app/runtimes/linux-x64/native/libSkiaSharp.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.16/libSkiaSharp.so: cannot open shared object file: No such file or directory
/app/libSkiaSharp.so: cannot open shared object file: No such file or directory
/app/runtimes/linux-x64/native/liblibSkiaSharp.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.16/liblibSkiaSharp.so: cannot open shared object file: No such file or directory
/app/liblibSkiaSharp.so: cannot open shared object file: No such file or directory
/app/runtimes/linux-x64/native/libSkiaSharp: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.16/libSkiaSharp: cannot open shared object file: No such file or directory
/app/libSkiaSharp: cannot open shared object file: No such file or directory
/app/runtimes/linux-x64/native/liblibSkiaSharp: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.16/liblibSkiaSharp: cannot open shared object file: No such file or directory
/app/liblibSkiaSharp: cannot open shared object file: No such file or directory

I checked the project dependencies and we have

but SkiaSharp.NativeAssets.Linux is not there, I suspect this might be the issue but would still like to know if its this or anything else.

Thank you.

@himanshu_surana

Cause

The exception you are encountering, System.TypeInitializationException, indicates that the SkiaSharp library is unable to load its native dependencies, specifically libSkiaSharp. This typically occurs when the required native assets are not included in your project, particularly for Linux environments.

Solution

To resolve this issue, ensure that the SkiaSharp.NativeAssets.Linux package is included in your project dependencies. This package contains the necessary native libraries for SkiaSharp to function correctly on Linux systems.

Code

You can add the required package using the following command in your terminal or package manager console:

dotnet add package SkiaSharp.NativeAssets.Linux

After adding the package, rebuild your project to ensure that the native libraries are properly included.

Next Steps

  1. Verify that the SkiaSharp.NativeAssets.Linux package is listed in your project dependencies.
  2. Rebuild your project to ensure all dependencies are correctly loaded.
  3. If the issue persists, check that your environment meets all requirements for running SkiaSharp, including any necessary system libraries.

Please follow these steps, and let me know if you need further assistance!

@himanshu_surana 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" />

Hey @vyacheslav.deryushev thanks for the help I will try and implement these once things look good I would get back and close the ticket.

Thanks again for the help

1 Like

Hi
I tried adding the SkiaSharp.NativeAssets.Linux.NoDependencies

But I continue to get the same exception.
I am using libgdiplus in the docker file, do i still need to setup the environment variable.

@himanshu_surana According to How to Run Aspose.Words in Docker|Aspose.Words for .NET and The type initializer for 'SkiaSharp.SKObject' threw an exception, this usually solves the problem.

Could you please provide the docker file and code you are using, or if possible a simple console application to reproduce the problem?