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

Created on 18 Jun 2020  路  30Comments  路  Source: mono/SkiaSharp

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

Most helpful comment

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.

All 30 comments

Most likely you don't have the FontConfig dependency for Linux. This needs to be installed via the platform tooling (apk or apt-get).

There is also the SkiaSharp.NativeAssets.Linux.NoDependencies that you can use instead of SkiaSharp.NativeAssets.Linux to avoid this, but you lose out on some advanced font features.

This usually does it for me:

sudo apt-get install -y libfontconfig1

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.

The other option is just to use Docker services.

Did you manage to resolve this?

Hi,

I'm running a Linux Web App in Azure (docker container based on the Alpine 3.11 image from MS)

Even I use the SkiaSharp.NativeAssets.Linux.NoDependencies package (version 2.80.1) I still get the exception:

System.TypeInitializationException: The type initializer for 'SkiaSharp.SKData' threw an exception.
2020-07-17T03:14:17.499823180Z: [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: Error loading shared library liblibSkiaSharp: No such file or directory
2020-07-17T03:14:17.499830080Z: [INFO]     at SkiaSharp.SkiaApi.sk_data_new_empty()
2020-07-17T03:14:17.499834080Z: [INFO]     at SkiaSharp.SKData..cctor()
2020-07-17T03:14:17.499837980Z: [INFO]     --- End of inner exception stack trace ---
2020-07-17T03:14:17.499841880Z: [INFO]     at SkiaSharp.SKData.Create(Stream stream)
2020-07-17T03:14:17.499846880Z: [INFO]     at SkiaSharp.SKImage.FromEncodedData(Stream data)

I use the following base image:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine3.11 AS base
and add the icu-libs package:
RUN apk add --no-cache icu-libs

Are there any other packages required?

@JMan7777 I had a look at this and I found the issue. Thanks for reporting.

The bug:
For some reason the Alpine build of no dependencies is still building with fontconfig. I have checks in CI for this, but it missed this? Not sure at this time. I will investigate and get a fix out ASAP.

The workaround:
Install fontconfig (not icu): RUN apk add --no-cache fontconfig

However, if you _can_ install fontconfig on your systems, then it might be better to just use the plain SkiaSharp.NativeAssets.Linux package as that has better font features.

Apologies for this. I'll have a look at the build tests to determine why this got through and ensure it does not happen again.

FYI, the way you can debug missing dependencies is to either do:

ldd libSkiaSharp.so

or

readelf -d libSkiaSharp.so

I got a fix going out with 2.80.2. Thanks for reporting.

Thx a lot.

Do we still need the icu-libs package for the NoDependencies version?

No. We don't need the icu at all. We are using harfbuzz, but that is in a separate NuGet as an option. Not required.

Exception
System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.\n ---> 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\n at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()\n at SkiaSharp.SKImageInfo..cctor()\n --- End of inner exception stack trace ---\n at SkiaSharp.SKImageInfo..ctor(Int32 width, Int32 height)\n at SkiaSharp.QrCode.Image.QrCode..ctor(String content, Vector2Slim qrSize)\n at SkiaSharp.QrCode.Image.QrCode..ctor(String content, Vector2Slim qrSize, SKEncodedImageFormat outputFormat)\n at ...

<PackageReference Include="SkiaSharp.QrCode" Version="0.3.2" /> <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.1" />

.net core 2.1, aws linux
Version with issue: 2.80.1

I had try to fix by
https://github.com/mono/SkiaSharp/issues/964 but didn't work

@IsoraTatsu This was unfortunately a regression in 2.80.x that will be fix in the next version coming soon

You can try out 2.80.2-preview.2 right now on the preview feed: https://aka.ms/skiasharp-eap/index.json

I will be pushing this version to nuget.org very soon.

tks

I still have this issue. Using 2.80.2-preview-33.

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.

I'm still having this issue using SkiaSharp.NativeAssets.Linux.NoDependencies 2.80.2.
Was there anything specific that others did to get this working?

There should not be anything.

I just checked, the only dependencies are:

Shared library: [libpthread.so.0]
Shared library: [libdl.so.2]
Shared library: [libm.so.6]
Shared library: [libc.so.6]
Shared library: [ld-linux-x86-64.so.2]

Obviously that doesn't help you...

What distro are you using? Is it x64?

Did the latest release fix this issue for anyone else?

I am facing this issue:

Environment: Azure Durable Function on Linux

Trying to convert a Docx to PDF using Syncfusion.

<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" />
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="18.2.0.58" />
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="18.2.0.58" />

Error:

System.DllNotFoundException at SkiaSharp.SkiaApi.sk_colortype_get_default_8888

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.
2020-09-17T04:51:19Z   [Error]   2d48902f2c514ec182d08839081dc318:4: Function 'ConvertToPdf (Activity)' failed with an error. Reason: 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 setting the LD_DEBUG environment variable: liblibSkiaSharp: cannot open shared object file: No such file or directory
   at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
   at SkiaSharp.SKImageInfo..cctor()
   --- End of inner exception stack trace ---
   at Syncfusion.DocIORenderer.Drawing.RenderHelper.GetBitmap(Int32 width, Int32 height)
   at Syncfusion.DocToPdfConverter.Rendering.PDFDrawingContext..ctor()
   at Syncfusion.DocIORenderer.DocIORenderer.ConvertToPDF(WordDocument wordDocument)
   at ConvertToPdfActivity.cs:line 62
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 591
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 537
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, IFunctionOutputDefinition outputDefinition, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 483
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 290. IsReplay: False. State: Failed. HubName: funcdocgenworkfloworchestratordev. AppName: func-docgen-workflow-orchestrator-dev. SlotName: Production. ExtensionVersion: 2.2.2. SequenceNumber: 16.

What happens when you remove SkiaSharp.NativeAssets.Linux but still keep SkiaSharp.NativeAssets.Linux.NoDependencies?

Both packages bring in the native binaries, so maybe it is getting confused...

I'll see if I can reproduce this if that still fails. Not sure why I haven't seen it.

Tried different combinations. Same issue :(

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>

But that is not what is supposed to be needed. The whole .NET Core things is to use the runtimes folder. That is the whole point of them.

I'll try repro this and see if it is maybe a bug in the publish step or the actual Azure Functions system. Might be that... They do have a slightly different system in the functions.

Exactly! It's supposed to be picking up necessary files based on the runtime. Thanks!

I am facing the same situation here. Any news on this?

PS: I manage to fix this by having SkiaSharp.NativeAssets.Linux.NoDependencies installed and copying the .so file just as @jaliyaudagedara mentioned
PS: Also works having just SkiaSharp.NativeAssets.Linux installed

I still have this problem. I have installed the following packages
c# <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" />

You can either import the normal Linux package or the NoDependencies not both.

I tested both modes. Single single and both.
c# 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

How can I fix such a problem in Docker?

Was this page helpful?
0 / 5 - 0 ratings