Unable to load shared library 'libSkiaSharp' or one of its dependencies on Linux
Asked Answered
K

3

9

I've built a .NET Core 6 application that runs without issue on my local Windows 11 machine. I've deployed it to an Ubuntu 20.04 server and I receive an error that it cannot load the libSkiaSharp shared library. I've seen other people report this issue but none of the suggestions are working for me.

Error

Error is received whenever SkiaSharp is used via code in a Linux environment enter image description here

Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: System.TypeInitializationException: The type initializer for 'SkiaSharp.SKData' threw an exception. <e LD_DEBUG environment variable: liblibSkiaSharp: cannot open shared object file: No such file or directory Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: fail: MyTest.Controllers.MyController[0] Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: The type initializer for 'SkiaSharp.SKData' threw an exception. Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: System.TypeInitializationException: The type initializer for 'SkiaSharp.SKData' threw an exception. Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: ---> 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 Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: at SkiaSharp.SkiaApi.sk_data_new_empty() Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: at SkiaSharp.SKData..cctor() Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: --- End of inner exception stack trace --- Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: at SkiaSharp.SKData.Create(IntPtr address, Int32 length) Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: at SkiaSharp.SKBitmap.Decode(ReadOnlySpan`1 buffer) Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: at SkiaSharp.SKBitmap.Decode(Byte[] buffer) Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: at Test.Common.Image.ImageManager.GenerateImage(ImageOptions MyPost, Details details) in C:\Users\TestUser\source\repos\Test.Web.Main\Test.Common.Image\ImageManager.cs:line 109 Feb 9 19:40:10 vmi1190349 dotnet-MyTest[9456]: at MyTest.Controllers.MyController.Get(ImageOptions MyPost) in C:\Users\TestUser\source\repos\Test.Web.Main\MyTest\Controllers\MyController.cs:line 84

Additional Details

I use SkiaSharp with text via SKTypeFace so I believe I need the SkiaSharp.NativeAssets.Linux package. However, after trying other suggestions and those not working, I removed the package and installed SkiaSharp.NativeAssets.Linux.NoDependencies. I'm still receiving the error though. My application takes user input to determine how SkiaSharp is used so I'm not hitting any code that is using SKTypeFace and I'm still receiving the same error while using the NoDependencies package.

My project has references to the following packages: enter image description here

I initially published the application with Target-Runtime = Portable but that didn't work. I tried moving the LibSkiaSharp.so file from the Runtimes directory to my web applications directory and that didn't work. I've also tried updating my publish settings to Target-Runtime=linux-x64 as this puts all of the project files in the root directory, redeployed, restarted the apache server and still receive the error.

Here are the file permissions for the deployed libSkiaSharp.so: enter image description here

I've run the ldd command and it appears to have all of the necessary dependencies for libSkiaSharp.so. enter image description here

I've also run the command to install libfontconfig1 as well

Koodoo answered 10/2, 2023 at 18:55 Comment(2)
Appreciate all the responses on this and hope that it helps others. I ended up switching to a Windows VPS and have not experienced any issues in that setup. So I'm unable to confirm if any of the answers would have worked in the original Linux environment as I no longer have access. Most suggest that using SkiaSharp.NativeAssets.Linux.NoDependences library resolved their issues but I still received the errors with that library.Koodoo
I believe we changed our azure funcs to 64-bit additionally but I would have to validate; it is working now.Dnieper
H
11

I've had this exact issue on an AppService over a linux AppServicePlan in Azure and got solved by referencing the following NuGet package in the project SkiaSharp.NativeAssets.Linux.NoDependencies.

Once deployed running over an Ubuntu worked fine, while running locally on my Windows 11 never raised any issue

Heyes answered 1/2 at 22:11 Comment(1)
This works in a raspberry as well.Foremast
A
0

I had a pretty similar issue. In my case the issue was the same message: dotnet can not find the libraries.

The nuget NativeAssets.Linux.NoDependencies is pretty helpful under controlled environments like dotnet docker's but outside of them can be a little headache and requires to maintainers to do some changes at the nuget package (for example, in AWS environments).

In the meanwhile... besides of libfontconfig1, did you try to install the missing libs libcdev, libexpat1, libuuid1, zlib1g and other references missing there by apt-installing?

Abba answered 20/2, 2023 at 12:28 Comment(1)
Thank you for your response. I ended up just switching to a Windows Server for my VPS so that I could get the site up and running. I currently don't have a way to go back and check to see if your suggestion will resolve it as the linux server I was initially using was deleted. If anyone else has this issue and can confirm that your suggestion resolves it then I will gladly mark this as the answer. Many thanks for your response!Koodoo
O
0

Installing the SkiaSharp.NativeAssets.Linux.NoDependencies NuGet package is working for me, we are using the azure fn and got the error

The type initializer for 'SkiaSharp.SKAbstractManagedStream' threw an exception. Unable to load shared library 'libSkiaSharp' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable:

Obfuscate answered 30/8 at 8:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.