Azure Functions (Linux) System.DllNotFoundException

Hi,
We have developed an Azure Function App that runs on the Flex Consumption Plan (Linux).
We are trying to convert a Word document to PDF.
We get following errors:

  • System.TypeInitializationException: The type initializer for ‘SkiaSharp.SKObject’ threw an exception.
  • System.DllNotFoundException: Unable to load shared library ‘libSkiaSharp’ or one of its dependencies.

We have installed the NuGet package SkiaSharp.NativeAssets.Linux.NoDependencies .
It is added to the csproj file.

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Aspose.BarCode" Version="24.11.0" />
    <PackageReference Include="Aspose.Imaging" Version="24.11.0" />
    <PackageReference Include="Aspose.OCR" Version="25.4.0" />
    <PackageReference Include="Aspose.PDF" Version="24.11.0" />
    <PackageReference Include="Aspose.Words" Version="24.11.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.3.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.2" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.5" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.23.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="3.119.1" />
  </ItemGroup>

Any suggestions on how to resolve this?

@wfbe

The errors you’re encountering, specifically System.DllNotFoundException for ‘libSkiaSharp’, indicate that the required native library for SkiaSharp is not available in your Azure Functions environment. Here are some steps you can take to resolve this issue:

  1. Ensure Native Dependencies: Since you are using SkiaSharp.NativeAssets.Linux.NoDependencies, verify that your Azure Function has access to the necessary native libraries. You may need to include the libSkiaSharp library manually in your project or ensure that it is available in the Azure environment.

  2. Use Docker Container: If you are deploying your Azure Function in a Linux environment, consider using a custom Docker container. This allows you to control the environment and ensure that all necessary libraries are included. You can create a Dockerfile that installs the required dependencies.

  3. Check Azure Function Plan: Ensure that your Azure Function is running on a plan that supports the required libraries. The Consumption Plan may have limitations, so consider switching to a Premium plan if necessary.

  4. Test Locally: Before deploying, test your function locally in a similar Linux environment to ensure that all dependencies are correctly resolved.

  5. Review Documentation: Check the official documentation for any specific requirements or configurations needed for running SkiaSharp in Azure Functions.

If these steps do not resolve the issue, consider reaching out to community forums or support for further assistance.

@wfbe With 24.11.1 version of Aspose.Words you should use 2.88.8 version of SkiaSharp.NativeAssets. There were breaking API changes in 3.119.1 of SkiaSharp. So they are not compatible.

Thanks, changing the version solved the issue. Is the newest Aspose.Words version compatible with the newest SkiaSharp.NativeAssets.Linux.NoDependencies library or should I pay attention when I upgrade?

@wfbe Yes, the latest version is compatible with SkiaSharp 3.119.0 version. You can check this in dependencies tab in NuGet:
https://www.nuget.org/packages/Aspose.Words/25.10.0#dependencies-body-tab