SkiaSharp: Unable to load shared library 'libSkiaSharp' or one of its dependencies - azure app service on Linux

Description

Just like the bug that was closed #1312 . Except this one is not using any other external libs, it’s just the Skia code.

A page that accesses Skia on Azure Linux fails. The same page on Windows desktop or Azure runs fine.

Exception

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
SkiaSharp.SkiaApi.sk_managedstream_set_procs(SKManagedStreamDelegates procs)

TypeInitializationException: The type initializer for 'SkiaSharp.SKAbstractManagedStream' threw an exception.
SkiaSharp.SKAbstractManagedStream..ctor(bool owns)

Raw

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
   at SkiaSharp.SkiaApi.sk_managedstream_set_procs(SKManagedStreamDelegates procs)
   at SkiaSharp.SKAbstractManagedStream..cctor()


<PackageReference Include="Azure.Cosmos" Version="4.0.0-preview3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.5" />
<PackageReference Include="Microsoft.Azure.Cosmos.Table" Version="2.0.0-preview" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
<PackageReference Include="Azure.ImageOptimizer" Version="1.1.0.39" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.5.0-preview.1" />
<PackageReference Include="SkiaSharp" Version="2.80.0-preview.14" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.0-preview.14" />
  • Version with issue: Both 1.6 and 2.8 preview (NUGET)
  • IDE: VS2019
  • Core 3.1, Azure Linux App Service

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 45 (16 by maintainers)

Commits related to this issue

Most upvoted comments

This also solved my issue, allowing Maui.Graphics tests to run on Linux in GitHub Actions 👍 🚀

<PackageReference Include="Microsoft.Maui.Graphics" Version="6.0.101-preview.9.512" />
<PackageReference Include="Microsoft.Maui.Graphics.Skia" Version="6.0.101-preview.9.512" />
<PackageReference Include="SkiaSharp" Version="2.88.0-preview.145" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.0-preview.145" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.0-preview.145" />

Previously my error was:


System.TypeInitializationException : The type initializer for 'SkiaSharp.SKFontManager' threw an exception.
----> 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
Stack Trace:
 at Microsoft.Maui.Graphics.Skia.SkiaFontService.InitializeFontFamilies()
     ...
--DllNotFoundException
   at SkiaSharp.SkiaApi.sk_fontmgr_ref_default()
   at SkiaSharp.SKFontManager..cctor()

I managed to get the dll using this package “HarfBuzzSharp.NativeAssets.Linux” Version=“2.8.2.1-preview.79”

Thanks for the hint @marciosarabando, installing the package “HarfBuzzSharp.NativeAssets.Linux” solved it for me as well (.NET 6 running on Raspberry Pi Linux).

I still have this problem. I have installed the following packages

<PackageReference Include="SkiaSharp" Version="2.80.2" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.2" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.2" />

This solved my issue (2.80.3) on openSUSE

I tested both modes. Single single and both.

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

After spending hours, issue turned out to be this:

The artifact folder looks like this.

  • {artifact}\runtimes

image

It has different libSkiaSharp.so inside each linux-* folder. But for some reason, those aren’t getting picked up.

Then I did this, basically copied libSkiaSharp.so to the root {artifact} folder. (linux-x64 in my case).

  <Target Name="CopyFilesAfterPublish" AfterTargets="_FunctionsPostPublish">
    <Copy SourceFiles="$(TargetDir)runtimes\linux-x64\native\libSkiaSharp.so" DestinationFolder="$(PublishDir)\bin\" />
  </Target>

image

And everything seems to be working just fine.

P.S:

If getting the artifact from Build (rather than Publish),

  <Target Name="CopyFilesAfterPublish" AfterTargets="PostBuildEvent">
    <Copy SourceFiles="$(TargetDir)runtimes\linux-x64\native\libSkiaSharp.so" DestinationFolder="$(TargetDir)\bin\" />
  </Target>

I think I need to find a way to detect this missing library on linux and give a slightly better exception to ask you to install the package.

This also solved my issue, allowing Maui.Graphics tests to run on Linux in GitHub Actions 👍 🚀

<PackageReference Include="Microsoft.Maui.Graphics" Version="6.0.101-preview.9.512" />
<PackageReference Include="Microsoft.Maui.Graphics.Skia" Version="6.0.101-preview.9.512" />
<PackageReference Include="SkiaSharp" Version="2.88.0-preview.145" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.0-preview.145" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.0-preview.145" />

Previously my error was:


System.TypeInitializationException : The type initializer for 'SkiaSharp.SKFontManager' threw an exception.
----> 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
Stack Trace:
 at Microsoft.Maui.Graphics.Skia.SkiaFontService.InitializeFontFamilies()
     ...
--DllNotFoundException
   at SkiaSharp.SkiaApi.sk_fontmgr_ref_default()
   at SkiaSharp.SKFontManager..cctor()

Thanks a lot! This is work for me.

Since this is Azure Linux App Service users cannot install anything.

I’ll try the NoDependencies since this purely image based, no fonts, which I’m assuming is text functions. I’ll report back.

Hi all,

Thanks, this forum helps to solve my problem.

I was having trouble using the lib QuestPDF running in a web api .net hosted in linux with the exception below:

“System.DllNotFoundException: Unable to load shared library ‘libHarfBuzzSharp’ or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibHarfBuzzSharp: cannot open shared object file: No such file or directory”

In windows environments it’s Ok, but to run on Linux I need to reference this package e insert the library libSkiaSharp.so manually in the project.

I managed to get the dll using this package “HarfBuzzSharp.NativeAssets.Linux” Version=“2.8.2.1-preview.79”

image

Thank you

removing SkiaSharp and adding SkiaSharp.NativeAssets.Linux.NoDependencies solved for me for .Net Core app working in debian docker container

Could you have a look at preview 36 that was just pushed out. I think we fix an issue that was coming up for web apps.