Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] SKiaSharp on linux can't find liblibSkiaSharp.so #2653

Open
1 task done
aodpi opened this issue Oct 19, 2023 · 32 comments
Open
1 task done

[BUG] SKiaSharp on linux can't find liblibSkiaSharp.so #2653

aodpi opened this issue Oct 19, 2023 · 32 comments

Comments

@aodpi
Copy link

aodpi commented Oct 19, 2023

Description

I'm trying to use SkiaSharp on .net core 7.0 to validate an image size. The app is running on a docker container on alpine linux.

I've installed the package SkiaSharp.NativeAssets.Linux in my project. After building the libSkiaSharp.so is present in the folder runtimtes/linux-musl-x64/native/ so it should work fine. But for some reason .net is try to load a file called liblibSkiaSharp.so in that folder. Is it a naming issue or something, where does the second lib word come from ?

The version of SkiaSharp I'm using is: 2.88.6

Code

The best way to share code for larger projects is a link to a GitHub repository: https://github.com/user/repo/tree/bug-123

But, you can also share a short block of code here:

using var imageStream = file.OpenReadStream();
using var bitmap = SKBitmap.Decode(imageStream);

if (bitmap == null)
{
    return new ValidationResult("The image could not be decoded.");
}

var size = bitmap.Info.Size;

if (size.Width > 512 || size.Height > 512)
{
    return new ValidationResult("The image dimensions are too large.");
}

Expected Behavior

The image should be loaded successfully.

Actual Behavior

Trying to decode an image throws an exception

Version of SkiaSharp

Other (Please indicate in the description)

Last Known Good Version of SkiaSharp

Other (Please indicate in the description)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Linux

Platform / Operating System Version

No response

Devices

No response

Relevant Screenshots

No response

Relevant Log Output

Error loading shared library libSkiaSharp: No such file or directory
Error loading shared library /app/runtimes/linux-musl-x64/native/liblibSkiaSharp: No such file or directory
Error loading shared library /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.12/liblibSkiaSharp: No such file or directory
Error loading shared library /app/liblibSkiaSharp: No such file or directory
Error loading shared library liblibSkiaSharp: No such file or directory

   at SkiaSharp.SkiaApi.sk_managedstream_set_procs(SKManagedStreamDelegates procs)
   at SkiaSharp.SKAbstractManagedStream..cctor()
   --- End of inner exception stack trace ---
   at SkiaSharp.SKAbstractManagedStream..ctor(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)

Code of Conduct

  • I agree to follow this project's Code of Conduct
@aodpi aodpi added the type/bug label Oct 19, 2023
@hsellentin
Copy link

hsellentin commented Nov 9, 2023

I'm experiencing this too on linux app service on Azure

Edit: issue came down to user error. SkiaSharp.NativeAssets.Linux.NoDependencies version 2.88.6, along with the base skiasharp 2.88.6 worked fine for me.

@jhariel8
Copy link

jhariel8 commented Nov 20, 2023

I seem to be having a similar issue. We are running our application in Azure Kubernetes Service on a Linux container.

Whenever we get images to start processing them, we get this exception:

System.TypeInitializationException: The type initializer for 'SkiaSharp.SKAbstractManagedStream' threw an exception.\nInner Exception: System.TypeInitializationException: 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.SKAbstractManagedStream..ctor(Boolean owns)\n at SkiaSharp.SKManagedStream..ctor(Stream managedStream, Boolean disposeManagedStream)\n at SkiaSharp.SKCodec.WrapManagedStream(Stream stream)\n at...

SkiaSharp.NativeAssets.Linux.NoDependencies is installed on this project. We did see a similar issue a while back and installing that package seemed to alleviate it. But we are fully up-to-date on SkiaSharp and the SkiaSharp.NativeAssets package (both are 2.88.6) and are seeing this issue suddenly pop up again.

I've tried several remedies that I've seen in the Issues here, including

  • adding "-r linux-x64" to the dotnet publish step in the Dockerfile
  • removing the SkiaSharp package and only installing the NativeAssets package
  • Adding the SkiaSharp.NativeAssets.Linux (with dependencies) instead of the NoDependencies version

Nothing so far as worked.

@jhariel8
Copy link

@aodpi Have you found any workarounds for this since the OP?

@aodpi
Copy link
Author

aodpi commented Nov 21, 2023

@aodpi Have you found any workarounds for this since the OP?

I haven't found any workarounds, I ended up not using Skiasharp anymore

@narojay
Copy link

narojay commented Dec 20, 2023

@aodpi Have you found any workarounds for this since the OP?

I haven't found any workarounds, I ended up not using Skiasharp anymore

same bug

@MarkWilds
Copy link

I also keep getting this. nothing works

@mattleibow
Copy link
Contributor

mattleibow commented Feb 28, 2024

Does things start to work if you use the SkiaSharp.NativeAssets.Linux.NoDependencies package? The No dependencies package is built without advanced font features to remove a dependency.

SkiaSharp depends on Font Config, so make sure you either use "NoDependencies" or you install the fontconfig package using the Linux package manager - apt/apt-get/apk

@hjrb
Copy link

hjrb commented Apr 3, 2024

sudo apt install fontconfig - no difference. Same error message.

@hjrb
Copy link

hjrb commented Apr 3, 2024

see https://curia.me/develop-graphical-linux-apps-with-avalonia-ui/
sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y && sudo apt-get autoremove -y
sudo apt install libice6
sudo apt install libsm6
sudo apt install libfontconfig1
This is to make a Avalonia based .NET 8 run. You might need less. But who cares about some bits...

@jhariel8
Copy link

Does things start to work if you use the SkiaSharp.NativeAssets.Linux.NoDependencies package? The No dependencies package is built without advanced font features to remove a dependency.

SkiaSharp depends on Font Config, so make sure you either use "NoDependencies" or you install the fontconfig package using the Linux package manager - apt/apt-get/apk

That's the package we are using but it did not fix this issue.

@alanrose
Copy link

@jhariel8 I also was running under a linux build with this issue. If it helps my fix was to uninstall all Skiasharp packages and only install the NoDependencies package

@Saganeiro
Copy link

I have a same issue on Azure pipeline with Docker.:

Error Message:
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

How to resolve that? Switching SkiaSharp / SkiaSharp.NativeAssets.Linux.NoDependencies / SkiaSharp.NativeAssets.Linux didn't help.

@moemura
Copy link

moemura commented Jul 12, 2024

@jhariel8 I also was running under a linux build with this issue. If it helps my fix was to uninstall all Skiasharp packages and only install the NoDependencies package

this works for Syncfusion libs, thanks

@moemura
Copy link

moemura commented Jul 12, 2024

I have a same issue on Azure pipeline with Docker.:

Error Message: 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

How to resolve that? Switching SkiaSharp / SkiaSharp.NativeAssets.Linux.NoDependencies / SkiaSharp.NativeAssets.Linux didn't help.

can you manually copy the .so files?

@Ragurajan21
Copy link

I am also using skiasharp 2.88.8 in .net 8 and running it Linux container getting the same issue , is there any workaround for this issue

@foxy0669
Copy link

foxy0669 commented Sep 5, 2024

@Ragurajan21 I've just had the same problem. It was working fine on windows but running with in a docker container I had the same problem. I installed SkiaSharp.NativeAssets.Linux 2.88.8 but that made no difference.

The fix for me was to install libfontconfig1

docker exec -it --user root bash
apt-get update
apt-get install libfontconfig1

I just need to add that into my Dockerfile for when I build the container

@JamestsaiTW
Copy link

JamestsaiTW commented Sep 15, 2024

Hi guys,
I build and run an AvaloniaUI app by WSL (Ubuntu). Similar problem occurred and got the following expections:

First:

System.TypeInitializationException: 'The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.'

InnerException:
System.DllNotFoundException: 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:  libfontconfig.so.1: cannot open shared object file: No such file or directory...

Second:

System.DllNotFoundException: 'Unable to load shared library 'libICE.so.6' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. 

Third:

System.DllNotFoundException: 'Unable to load shared library 'libSM.so.6' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace

The fix for me was to install libfontconfig1, libice6, and libsm6 to my WSL (Ubuntu).

sudo apt install libfontconfig1
sudo apt install libice6
sudo apt install libsm6

Hope it will help you guys.

@TopperDEL
Copy link

sudo apt install libfontconfig1
sudo apt install libice6
sudo apt install libsm6

This did the trick on my end, too! Thanks for that!

@mattleibow
Copy link
Contributor

If there are still issues with linux and docker, please create a repo with the code and docker file so I can check.

@Kyeong-min
Copy link

@jhariel8 I also was running under a linux build with this issue. If it helps my fix was to uninstall all Skiasharp packages and only install the NoDependencies package

This worked for me.
I deleted all SkiaSharp libarary from nuget manager, installed the SkiaSharp.NativeAssets.Linux.NoDependencies package, and installed SkiaSharp as a dependency.
And it worked.

@Saganeiro
Copy link

Still didn’t work.

@mattleibow
Copy link
Contributor

@Saganeiro please attach a repro sample or github link so I can check it out.

@foxy0669
Copy link

My app is a Blazor server application and I build my container under WSL. This solutions works fine for me, building for Windows WSL or Linux hosts.

Run this before building the container

docker run --rm --privileged multiarch/qemu-user-static --reset -p yes -c yes

I then added the following under the base container to my Dockerfile.

FROM mcr.microsoft.com/dotnet/aspnet:8.0.2-bookworm-slim-arm64v8 AS base

USER root
RUN echo "deb http://deb.debian.org/debian bookworm contrib non-free" > /etc/apt/sources.list.d/contrib.list
RUN apt-get update && apt-get install -y libfontconfig1 ttf-mscorefonts-installer fontconfig && apt-get clean &&
 rm -rf /var/lib/apt/lists/*

@lloydjatkinson
Copy link

lloydjatkinson commented Dec 9, 2024

I also encounter this. None of the usual suggestions of NoDependencies work. I even copied libSkiaSharp.o from the NuGet and it does not work.

For what it’s worth I’ve been trying this on a Raspberry Pi 3.

Unhandled exception. System.TypeInitializationException: The type initializer for 'SkiaSharp.SKObject' threw an exception.
 ---> System.DllNotFoundException: 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:
/lib/arm-linux-gnueabihf/libm.so.6: version `GLIBC_2.29' not found (required by /home/pi/wordsearch/src/WordSearch.Ui.Web.Temporary/bin/Debug/net8.0/runtimes/linux-arm/native/libSkiaSharp.so)
/home/pi/.dotnet/shared/Microsoft.NETCore.App/8.0.11/libSkiaSharp.so: cannot open shared object file: No such file or directory

@kirse
Copy link

kirse commented Dec 12, 2024

I also encounter this. None of the usual suggestions of NoDependencies work. I even copied libSkiaSharp.o from the NuGet and it does not work.

I was having similar issues on .NET 8.0 and a RHEL / Rocky / CentOS platform... downgrading SkiaSharp.NativeAssets.Linux.NoDependencies to 2.88.6 worked for me. SkiaSharp.NativeAssets.Linux v2.88.6 also worked.

Check your GLIBC version and see if you can upgrade that or downgrade the above dep to one that aligns.

@Ghostbird
Copy link

Ghostbird commented Dec 24, 2024

We finally upgraded from SkiaSharp 2.88.9 to 3.116.0 and our environment broke.
When using this Skiasharp version no runtime libraries for linux-musl-x64 are published:

image

@lloydjatkinson
Copy link

I’m facing the opposite problem; only x64 is working for me.

@Ghostbird
Copy link

Ghostbird commented Dec 24, 2024

I’m facing the opposite problem; only x64 is working for me.

This is not completely clear, as there are 4 different x64 runtimes. Did you specifically mean the linux-musl-x64 architecture I mentioned? The other 3 x64 runtimes publish correctly for me.

@KoertLichtendonk
Copy link

Facing the exact same issue, coincidentally also while working with Bitmaps. I added the following bits to my Dockerfile, but unfortunately this doesn't help either, although I am using Linux.NoDependencies. I found that on Windows I need to move the libSkiaSharp.dll from runtimes to the project folder, so I tried that here as well.

RUN apt-get update && apt-get install -y libfontconfig1 libice6 libsm6
COPY --from=build /app/out/runtimes/linux-x64/native/libSkiaSharp.so gamemode/
COPY --from=build /app/out/runtimes/linux-x64/native/libSkiaSharp.so /usr/lib/
RUN chmod 755 /usr/lib/libSkiaSharp.so
RUN ldconfig

I am using SkiaSharp in a 32 bit project (on a 64 bit system, though), so I suppose that could also be it, considering there is only a x64 .so.

I'm on v3.116.1. Happy to provide more information if necessary.

@Ghostbird
Copy link

I'm using the normal SkiaSharp with the dependencies installed into our alpine image. But the problem for me is that dotnet publish will not put a libskiasharp.so file into the runtimes/linux-musl-x64 folder, even if it does do so in the folders of each other architecture. So it seems a build issue, not a runtime non-installed dependency.

@Ghostbird
Copy link

I tried using SkiaSharp.NativeAssets.Linux.NoDependencies and when I publish using that NuGet package, I do get a libSkiaSharp.so in my linux-musl-x64 folder.

Can it be that the SkiaSharp.NativeAssets.Linux package build somehow no longer includes the libSkiaSharp.so file for the linux-musl-x64 architecture? Or is there a new complie-time dependency, that's specific to building for this architecture?

For now I'll switch to the NoDependencies package, but it's annoying that I'll have to redesign our base docker images.

@aodpi
Copy link
Author

aodpi commented Dec 30, 2024

Having SkiaSharp.NativeAssets.Linux version 2.88.9 installed, I can confirm that everything works as expected. Updating to newer versions brings this issue back up again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready For Work
Development

No branches or pull requests