DllNotFoundException using SkiaSharp 1.68 on Linux
Asked Answered
R

2

11

Using SkiaSharp 1.68.0 with .NET Core 2.2 on Linux and get this error when trying to use Decode on a jpeg-memory-stream (same code works on Windows):

System.TypeInitializationException: The type initializer for 'SkiaSharp.SKAbstractManagedStream' 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_managedstream_set_delegates(IntPtr pRead, IntPtr pPeek, IntPtr pIsAtEnd, IntPtr pHasPosition, IntPtr pHasLength, IntPtr pRewind, IntPtr pGetPosition, IntPtr pSeek, IntPtr pMove, IntPtr pGetLength, IntPtr pCreateNew, IntPtr pDestroy)
   at SkiaSharp.SKAbstractManagedStream..cctor()
   --- End of inner exception stack trace ---
   at SkiaSharp.SKAbstractManagedStream..ctor(Boolean owns)
   at SkiaSharp.SKManagedStream..ctor(Stream managedStream, Boolean disposeManagedStream, Boolean owns)
   at SkiaSharp.SKManagedStream..ctor(Stream managedStream, Boolean disposeManagedStream)
   at SkiaSharp.SKCodec.WrapManagedStream(Stream stream)
   at SkiaSharp.SKCodec.Create(Stream stream, SKCodecResult& result)
   at SkiaSharp.SKCodec.Create(Stream stream)
   at SkiaSharp.SKBitmap.Decode(Stream stream) 

The inner-most error message seem to be "No such file or directory" which is strange since I'm decoding a memory-stream. This works on Windows and it have worked on Linux before I upgraded to .NET Core 2.2 and latest SkiaSharp.

I have tried setting the LD_DEBUG env variable as suggested in the error message but that didn't do much. Not sure what to set it to really. Tried 'all' but that didn't result in any more detailed log.

Found a thread that suggests installing SkiaSharp.NativeAssets.Linux as a solution, but unfortunately that didn't help. Do I need to target Linux-x64 runtime when building/publishing? Have tried different combinations but couldn't detect any difference. (I'm building with dotnet cli in a Docker-file on Linux over ssh with putty. Pretty much default Docker-file as generated by VS:latest)

Another suggestion was to install libSkiaSharp.so manually and also apt-get install libfontconfig1, but unfortunately apt-get is not available on Synology DSM.

Restrictive answered 9/12, 2018 at 13:53 Comment(0)
C
13

Installing Linux dependency NuGet Package will solve this issue SkiaSharp.NativeAssets.Linux.NoDependencies https://www.nuget.org/packages/SkiaSharp.NativeAssets.Linux.NoDependencies

Christine answered 17/7, 2020 at 14:34 Comment(0)
S
11

I had the same problem running SkiaSharp with .Net Core 2.2 on Linux.

First, I installed the NuGet package SkiaSharp.NativeAssets.Linux (that you mention above) and made sure that the libSkiaSharp.so file was copied into the same directory as the rest of the DLLs.

I still received the error.

Next, I connected a shell to my container and I listed the dependencies using the command: ldd libSkiaSharp.so

I found out that I was missing libfreetype6 and libfontconfig1.

As my environment uses Docker, I simply added some commands to install these extra dependencies in my docker file:

FROM microsoft/dotnet:aspnetcore-runtime RUN apt-get update RUN apt-get install -y libfreetype6 RUN apt-get install -y libfontconfig1

Now the application works.

Can you try adding these commands to your Docker file?

Squeaky answered 5/3, 2019 at 11:49 Comment(3)
Thanks for the solution. You said "and made sure that the libSkiaSharp.so file was copied into the same directory as the rest of the DLLs" and I didn't know if an extra step was required to make this happen, but no, the files just ended up where they belonged.Rocca
I was facing a similar problem, and was able to use a similar solution. I tested it that BOTH ot the steps are needed, neither one of them alone solved the problem. In my case it was enough to install only libfontconfig1 with apt-get, I didn't need to install the other library.Cleaver
FYI: There's a new version of SkiaSharp without any dependencies that works great on Synology as well, without having to install any font-libs (works great with resizing images but without the text-rendering-support)Restrictive

© 2022 - 2024 — McMap. All rights reserved.