dotnet / sdk-container-builds

Libraries and build tooling to create container images from .NET projects using MSBuild
https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container
MIT License
176 stars 30 forks source link

It is not properly picking SkiaSharp.NativeAssets.Linux.NoDependencies DLLs from infrastructure layer project #475

Closed tomasfil closed 5 months ago

tomasfil commented 12 months ago

Hello,

We are trying to use this library, but if we publish to docker, it is not correctly loading SkiaSharp.NativeAssets.Linux.NoDependencies resulting into below exception.

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 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
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.8/libSkiaSharp.so: cannot open shared object file: No such file or directory
/app/liblibSkiaSharp.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.8/liblibSkiaSharp.so: cannot open shared object file: No such file or directory
/app/libSkiaSharp: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.8/libSkiaSharp: cannot open shared object file: No such file or directory
/app/liblibSkiaSharp: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.8/liblibSkiaSharp: cannot open shared object file: 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.SKBitmap.Decode(Stream stream)
baronfel commented 11 months ago

Hi @tomasfil - is there a sample project or a way I could repro this myself? What this tooling does is a normal Publish operation (which should collect all of the correct native assets) and then a re-packaging of the assets from that Publish, so I'd expect native assets to be handled correctly in the general case. It might also help to have an aka.ms/binlog available (though those files may have sensitive data in them).

ghhv commented 6 months ago

This is still an issue in .NET 8 and the fix is not obvious so here is what worked for me.. You must add this to your project file - note there is no using statement for the Linux package. Just add it to the .proj file.

 <PackageReference Include="SkiaSharp" Version="2.88.6" ExcludeAssets="native" />
 <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.6" />

Do not include the Dependencies version - aka <PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />

If you have included that previously you must find the published libSkiaSharp.so file and delete it from the publish folder otherwise it does not get replaced with the correct one.

Publish again and it should work.

tmitchel2 commented 6 months ago

@ghhv Thanks you got me on the right track with that.... I have to include another one though to get mine working

<PackageReference Include="SkiaSharp" Version="2.88.6" ExcludeAssets="native" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.6" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0" />
baronfel commented 5 months ago

Thanks @ghhv - @tmitchel2 that cover it for you?

tmitchel2 commented 5 months ago

All good with me @baronfel

djinete commented 4 months ago

I'm using mcr.microsoft.com/dotnet/aspnet:6.0 AS base

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base and adding this line to the Dockerfile

RUN apt-get update && apt-get install -y libfontconfig1

Solve the problem using SkiaSharp.NativeAssets.Linux(2.88.7) and SkiaSharp.NativeAssets.Linux.NoDependencies (2.88.7)