Aspose.Words throws SkiaSharp DLL Not Found Exception on save as PDF

The following works in a Azure App Service Windows, but it fails with SkiaSharp DLL not found exception:

private void MergeAllSingleFields(Document wordDocumentTemplate, Dictionary<string, string> flattenedData)
{
    var fieldNames = flattenedData.Keys.ToArray();
    var fieldValues = flattenedData.Values.Cast<object>().ToArray();

    wordDocumentTemplate.MailMerge.Execute(fieldNames, fieldValues);
    wordDocumentTemplate.UpdateFields();
    wordDocumentTemplate.UpdatePageLayout();
}
private Document ReplaceWordDocPlaceholders(Document wordDocumentTemplate, JObject data)
{
    // 1) Merge single fields
    var flattenedJson = FlattenJson(data);
    MergeAllSingleFields(wordDocumentTemplate, flattenedJson);

    // 2) Flatten the doc (to expose conditionals)
    using var tempStream = new MemoryStream();
    wordDocumentTemplate.Save(tempStream, SaveFormat.Docx);
    tempStream.Position = 0;
    var flattenedDoc = new Document(tempStream);

    // 3) Identify all table placeholders
    var existingTables = GetTablePlaceholders(flattenedDoc);

    // 4) Merge arrays via ExecuteWithRegions
    foreach (var tableName in existingTables)
    {
        var token = data.SelectToken(tableName);
        if (token is JArray array)
        {
            var ds = new JsonMailMergeDataSource(tableName, array);
            flattenedDoc.MailMerge.ExecuteWithRegions(ds);
        }
    }


    flattenedDoc.MailMerge.DeleteFields();
    flattenedDoc.UpdateFields();
    flattenedDoc.UpdatePageLayout();


    return flattenedDoc;
}

 private void MergeAllSingleFields(Document wordDocumentTemplate, Dictionary<string, string> flattenedData)
 {
     var fieldNames = flattenedData.Keys.ToArray();
     var fieldValues = flattenedData.Values.Cast<object>().ToArray();

     wordDocumentTemplate.MailMerge.Execute(fieldNames, fieldValues);
     wordDocumentTemplate.UpdateFields();
     wordDocumentTemplate.UpdatePageLayout();
 }

Exception Stack

Inner stack trace
Ok

2025-03-07T10:32:43.3702057

  Ok

2025-03-07T10:32:43.3702057

/opt/startup/startup.sh: line 20:  1116 Aborted                 (core dumped) dotnet "InstaFormEngineAPI.dll"

  Ok

2025-03-07T10:32:31.0942902

  Ok

2025-03-07T10:32:31.0942902

   at SkiaSharp.SKNativeObject.Finalize()

  Ok

2025-03-07T10:32:31.0942854

   at SkiaSharp.SKBitmap.Dispose(Boolean disposing)

  Ok

2025-03-07T10:32:31.0942808

   at SkiaSharp.SKObject.Dispose(Boolean disposing)

  Ok

2025-03-07T10:32:31.0942754

   at SkiaSharp.SKNativeObject.Dispose(Boolean disposing)

  Ok

2025-03-07T10:32:31.0942567

   at SkiaSharp.SKObject.set_Handle(IntPtr value)

  Ok

2025-03-07T10:32:31.094252

   at SkiaSharp.SKObject.DeregisterHandle(IntPtr handle, SKObject instance)

  Warning

2025-03-07T10:32:31.0942473

   --- End of inner exception stack trace ---

  Ok

2025-03-07T10:32:31.0942425

   at SkiaSharp.SKObject..cctor()

  Ok

2025-03-07T10:32:31.0942378

   at SkiaSharp.SkiaSharpVersion.CheckNativeLibraryCompatible(Boolean throwIfIncompatible)

  Ok

2025-03-07T10:32:31.0942331

   at SkiaSharp.SkiaSharpVersion.get_Native()

  Ok

2025-03-07T10:32:31.0942283

   at SkiaSharp.SkiaApi.sk_version_get_milestone()

  Ok

2025-03-07T10:32:31.0942236

  Error

2025-03-07T10:32:31.0942186

/home/site/wwwroot/liblibSkiaSharp: cannot open shared object file: No such file or directory

  Error

2025-03-07T10:32:31.0942135

/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.12/liblibSkiaSharp: cannot open shared object file: No such file or directory

  Error

2025-03-07T10:32:31.0942084

/home/site/wwwroot/libSkiaSharp: cannot open shared object file: No such file or directory

  Error

2025-03-07T10:32:31.0942034

/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.12/libSkiaSharp: cannot open shared object file: No such file or directory

  Error

2025-03-07T10:32:31.0941984

/home/site/wwwroot/liblibSkiaSharp.so: cannot open shared object file: No such file or directory

  Error

2025-03-07T10:32:31.0941931

/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.12/liblibSkiaSharp.so: cannot open shared object file: No such file or directory

  Error

2025-03-07T10:32:31.094188

/home/site/wwwroot/libSkiaSharp.so: cannot open shared object file: No such file or directory

  Error

2025-03-07T10:32:31.0941826

/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.12/libSkiaSharp.so: cannot open shared object file: No such file or directory
 

This makes my Aspose.Words integration not work.

@JustinOneshield

The SkiaSharp DLL Not Found Exception you are encountering when saving a document as PDF using Aspose.Words is likely due to missing native dependencies required by SkiaSharp, which is used for rendering graphics in Aspose.Words.

To resolve this issue, you need to ensure that the necessary native assets for SkiaSharp are included in your project, especially when running in a Linux environment like Azure App Service. Here are the steps you can follow:

  1. Install SkiaSharp Native Assets: Make sure to include the SkiaSharp.NativeAssets.Linux NuGet package in your project. This package provides the native Skia library required for Linux environments.

  2. Update Your Dockerfile: If you are using Docker, your Dockerfile should include commands to install the required libraries. For example, you need to install libfontconfig1, which is necessary for SkiaSharp to function properly. Here’s a sample snippet for your Dockerfile:

    FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
    WORKDIR /app
    RUN apt-get update && apt-get install -y libfontconfig1
    COPY . ./
    RUN dotnet publish -c Release -o out
    FROM mcr.microsoft.com/dotnet/core/runtime:2.2 AS runtime
    WORKDIR /app
    COPY --from=build /app/out ./
    ENTRYPOINT ["dotnet", "YourApp.dll"]
    
  3. Check for Other Dependencies: Depending on your specific environment, you may need to install additional libraries. For example, if you are using Alpine Linux, you might need to install fontconfig and harfbuzz as well.

  4. Test Locally: Before deploying to Azure, test your application locally in a similar environment (e.g., using Docker) to ensure that all dependencies are correctly resolved.

By following these steps, you should be able to resolve the SkiaSharp DLL Not Found Exception and successfully save documents as PDF using Aspose.Words.

If you continue to experience issues, please provide additional details about your environment and setup for further assistance.

@JustinOneshield Aspose.Words for .NET Standard and .NET Core 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.

Thanks Alexey,
How do I know which I need with no dependencies, or with?
My project is a .Net 8 Web API with no GUI.

@JustinOneshield 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.

1 Like