Skip to content
Advertisement

Deploy SkiaSharp on a container running .NET 6 Alpine Linux

SkiaSharp fails at runtime when deployed to an alpine linux container, using .NET 6.0 with the following error:

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 ZXing.SkiaSharp.Rendering.SKBitmapRenderer.Render(BitMatrix matrix, BarcodeFormat format, String content, EncodingOptions options) at ZXing.BarcodeWriter`1.Write(String contents)

I have tried (with no effect)

  • Adding a reference to SkiaSharp.NativeAssets.Linux
  • Swapping with a reference to SkiaSharp.NativeAssets.Linux.NoDepedencies
  • Swapping with a reference to StoneCold.SkiaSharp.NativeAssets.AlpineLinux
  • Rolling back version from 2.88.3 to 2.80.3
  • Copying libSkiaSharp.so /usr/lib/
  • Adding my publish directory to LD_LIBRARY_PATH

Project file

JavaScript

My current Dockerfile (simplified)

JavaScript

Any help would be appreciated.

Update: Working Solution Thanks @omajid

JavaScript

Advertisement

Answer

You are targeting your application for alpine, but you are running it in the final container, which is based on base:

JavaScript

And base is just

JavaScript

And that’s a Debian 11 image:

JavaScript

So, you probably want to switch the base container to alpine before running it? Alternatively, target linux-x64 instead of alpine-x64?

Also, Microsoft’s recommendation is to use generic RIDs (eg, linux-musl-x64, or linux-arm64) instead of specific ones (eg alpine-x64 or rhel.8-arm64).

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement