Problem with SkiaSharp on Linux

Hi Aspose team,

We use Aspose.Cells 23.3.0 in our AzureFunction. Everything works fine on Windows.
On Linux, when we call new Workbook(), we get this error:

2024-04-19T09:48:26.226538934Z: [ERROR] Unhandled exception. System.TypeInitializationException: The type initializer for ‘SkiaSharp.SKObject’ threw an exception.
2024-04-19T09:48:26.226589134Z: [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: liblibSkiaSharp: cannot open shared object file: No such file or directory
2024-04-19T09:48:26.226598835Z: [ERROR] at SkiaSharp.SkiaApi.sk_version_get_milestone()
2024-04-19T09:48:26.226603935Z: [ERROR] at SkiaSharp.SkiaSharpVersion.get_Native()
2024-04-19T09:48:26.226608035Z: [ERROR] at SkiaSharp.SkiaSharpVersion.CheckNativeLibraryCompatible(Boolean throwIfIncompatible)
2024-04-19T09:48:26.226611935Z: [ERROR] at SkiaSharp.SKObject…cctor()
2024-04-19T09:48:26.226615635Z: [ERROR] — End of inner exception stack trace —
2024-04-19T09:48:26.226619835Z: [ERROR] at SkiaSharp.SKObject.DeregisterHandle(IntPtr handle, SKObject instance)
2024-04-19T09:48:26.226623735Z: [ERROR] at SkiaSharp.SKObject.set_Handle(IntPtr value)
2024-04-19T09:48:26.226627335Z: [ERROR] at SkiaSharp.SKNativeObject.Dispose(Boolean disposing)
2024-04-19T09:48:26.226631035Z: [ERROR] at SkiaSharp.SKNativeObject.Finalize()
2024-04-19T09:48:26.226649635Z: [INFO] Unhandled exception on 04/19/2024 09:48:26: System.TypeInitializationException: The type initializer for ‘SkiaSharp.SKObject’ threw an exception.
2024-04-19T09:48:26.226654935Z: [INFO] —> 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: liblibSkiaSharp: cannot open shared object file: No such file or directory
2024-04-19T09:48:26.226660235Z: [INFO] at SkiaSharp.SkiaApi.sk_version_get_milestone()
2024-04-19T09:48:26.226664435Z: [INFO] at SkiaSharp.SkiaSharpVersion.get_Native()
2024-04-19T09:48:26.226668435Z: [INFO] at SkiaSharp.SkiaSharpVersion.CheckNativeLibraryCompatible(Boolean throwIfIncompatible)
2024-04-19T09:48:26.226672335Z: [INFO] at SkiaSharp.SKObject…cctor()
2024-04-19T09:48:26.226676535Z: [INFO] — End of inner exception stack trace —
2024-04-19T09:48:26.226680635Z: [INFO] at SkiaSharp.SKObject.DeregisterHandle(IntPtr handle, SKObject instance)
2024-04-19T09:48:26.226684335Z: [INFO] at SkiaSharp.SKObject.set_Handle(IntPtr value)
2024-04-19T09:48:26.226687636Z: [INFO] at SkiaSharp.SKNativeObject.Dispose(Boolean disposing)
2024-04-19T09:48:26.226690936Z: [INFO] at SkiaSharp.SKNativeObject.Finalize()

This leads to container restart and as a result unexpected azure function behavior.

We use these libraries:
SkiaSharp 2.88.7
SkiaSharp.NativeAssets.Linux.NoDependencies 2.88.7

Tried different versions, 2.88.8, 2.88.6, 2.88.3, but no success.

Please, advise how to solve this issue.

@sergeykavaliou
Could you try to directly use SkiaSharp to draw an image without Aspose.Cells on AzureFunction linux?

removed new Workbook and tried this
using (SKPaint textPaint = new SKPaint { TextSize = 48 })

yes, we have the same issue.

@sergeykavaliou,

The issue may not be with Aspose.Cells. We suggest you to try browsing internet to find relevant threads/documents to figure out your issue.
e.g.
https://github.com/mono/SkiaSharp/issues/2607

Thank you! will investigate

@sergeykavaliou
You are welcome. If you have any questions, please feel free to contact us.

@sergeykavaliou ,

Also, try the solution at [BUG] Unable to load DLL 'libSkiaSharp' or one of its dependencies on Azure Functions · Issue #1001 · mono/SkiaSharp · GitHub.

Please let us know the solution if you fixed the issue on AzureFunction Linux.

@sergeykavaliou, did you ever find a solution for this?

@wfbe,

Did you try the solution mentioned at [BUG] Unable to load DLL ‘libSkiaSharp’ or one of its dependencies on Azure Functions · Issue #1001 · mono/SkiaSharp · GitHub?

Hi @wfbe,

  1. I updated some packages (Microsoft.Azure.WebJobs.Extensions.DurableTask to 2.13.1, Microsoft.NET.Sdk.Functions to 4.2.0, SkiaSharp.NativeAssets.Linux.NoDependencies to 2.88.6)
  2. Updated Azure pipeline
    Old approach
  • task: DotNetCoreCLI@2
    displayName: ‘.Net Core - Build AZ Function’
    inputs:
    command: ‘build’
    projects: ‘**/Project.csproj’
    arguments: ‘–no-restore --output $(build.artifactstagingdirectory)/azurefunctions’

  • task: AzureFunctionApp@1
    displayName: ‘Deploy Azure Functions’
    inputs:
    azureSubscription: ‘${{ parameters.azureServiceConnection }}’
    appType: functionApp
    appName: $(azfName)
    package: ‘$(Agent.BuildDirectory)/az_func/azurefunctions’
    configurationStrings: ‘-WEBSITE_RUN_FROM_PACKAGE false’

New approach

  • task: DotNetCoreCLI@2
    displayName: ‘Publish AZ Function’
    inputs:
    command: publish
    projects: ‘**/Project.csproj’
    publishWebProjects: false
    modifyOutputPath: false
    zipAfterPublish: false
    arguments: ‘-c Release --output $(System.DefaultWorkingDirectory)/azf’

  • task: ArchiveFiles@2
    displayName: “Archive files”
    inputs:
    rootFolderOrFile: “$(System.DefaultWorkingDirectory)/azf”
    includeRootFolder: false
    archiveType: zip
    archiveFile: “$(Build.ArtifactStagingDirectory)/azf.zip”
    replaceExistingArchive: true

  • task: AzureFunctionApp@2
    displayName: ‘Deploy Azure Functions’
    inputs:
    azureSubscription: ‘${{ parameters.azureServiceConnection }}’
    appType: functionAppLinux
    appName: $(azfName)
    package: ‘$(Agent.BuildDirectory)/azf/azf.zip’

@sergeykavaliou
Thank you for sharing. It seems that you have solved the issue by updating the packages and Azure pipeline. It will be very helpful for other users who have encountered the same issue.

@wfbe Would you like to try the solution provided by “sergeykavaliou”? Please let us know your feedback.

@John.He , using a lower SkiaSharp version solved my issue. I had opened a separate topic in the meantime: Azure Functions (Linux) System.DllNotFoundException - Free Support Forum - aspose.com

@wfbe,

It’s good to hear that you resolved your issue by downgrading the SkiaSharp version. Please don’t hesitate to reach out to us anytime if you have additional questions or feedback.