Skip to content

[BUG] Unable to load shared Library LibskiaSharp on RHEL9 based docker image. #3612

@Schoof-T

Description

@Schoof-T

Description

I am using LiveCharts2 RC 6.1, which uses SkiaSharp to generate a Gauge Chart.
I am trying to convert this to a bitmap and base64 (for usage in PDF generation).

This works perfectly in my local (Windows) machine, but after I deploy to our local docker containers (based on RHEL9), this doesn't work, and I get the error below: Unable to load shared library 'libSkiaSharp'.

The exception occurs on this line of code:
using var bitmap = new SkiaSharp.SKBitmap(totalStockGaugeChart.Width, totalStockGaugeChart.Height);

I have tried adding the Nuget Packages:

  • SkiaSharp.NativeAssets.Linux
  • SkiaSharp.NativeAssets.Linux.NoDependencies

But those did not make a difference.

Ultimately, after a day of trial and error I managed to get it to work by adjusting my docker file, and adding the following:
I do not need the SkiaSharp.NativeAssets.Linux either than.

#SKIASHARP
RUN microdnf install -y \
    fontconfig \
    freetype \
    freetype-devel \
    libpng \
    expat \
    && microdnf clean all
# SKIASHARP
# fontconfig and its dependencies
COPY --from=build /usr/lib64/libfontconfig.so.1 /usr/lib64/libfontconfig.so.1
COPY --from=build /usr/lib64/libfontconfig.so.1.12.0 /usr/lib64/libfontconfig.so.1.12.0
COPY --from=build /usr/lib64/libfreetype.so.6 /usr/lib64/libfreetype.so.6
COPY --from=build /usr/lib64/libfreetype.so.6.17.4 /usr/lib64/libfreetype.so.6.17.4
COPY --from=build /usr/lib64/libpng16.so.16 /usr/lib64/libpng16.so.16
COPY --from=build /usr/lib64/libpng16.so.16.37.0 /usr/lib64/libpng16.so.16.37.0
COPY --from=build /usr/lib64/libharfbuzz.so.0 /usr/lib64/libharfbuzz.so.0
COPY --from=build /usr/lib64/libharfbuzz.so.0.20704.0 /usr/lib64/libharfbuzz.so.0.20704.0
COPY --from=build /usr/share/fontconfig /usr/share/fontconfig
COPY --from=build /etc/fonts /etc/fonts
COPY --from=build /usr/lib64/libgraphite2.so.3 /usr/lib64/libgraphite2.so.3
COPY --from=build /usr/lib64/libgraphite2.so.3.2.1 /usr/lib64/libgraphite2.so.3.2.1

Code

        using var bitmap = new SkiaSharp.SKBitmap(totalStockGaugeChart.Width, totalStockGaugeChart.Height);
        using var canvas = new SkiaSharp.SKCanvas(bitmap);
        totalStockGaugeChart.DrawOnCanvas(canvas);

        using var image = SkiaSharp.SKImage.FromBitmap(bitmap);
        using var data = image.Encode(SkiaSharp.SKEncodedImageFormat.Png, 100);

        return System.Convert.ToBase64String(data.ToArray());

Expected Behavior

I expected the code to generate my Base64String, and not crash.

Actual Behavior

I get an exception:

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 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/lib64/dotnet/shared/Microsoft.NETCore.App/10.0.3/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/lib64/dotnet/shared/Microsoft.NETCore.App/10.0.3/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/lib64/dotnet/shared/Microsoft.NETCore.App/10.0.3/libSkiaSharp: cannot open shared object file: No such file or directory
/app/liblibSkiaSharp: cannot open shared object file: No such file or directory
/usr/lib64/dotnet/shared/Microsoft.NETCore.App/10.0.3/liblibSkiaSharp: cannot open shared object file: No such file or directory
   at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
   at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
   at SkiaSharp.SKImageInfo..cctor()
   --- End of inner exception stack trace ---
   at SkiaSharp.SKImageInfo..ctor(Int32 width, Int32 height)

Version of SkiaSharp

3.116.0 (Current)

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

  • registry.access.redhat.com/ubi9/dotnet-100:9.7-1771893416 AS base
  • rhel 9

Devices

No response

Relevant Screenshots

No response

Relevant Log Output

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 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/lib64/dotnet/shared/Microsoft.NETCore.App/10.0.3/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/lib64/dotnet/shared/Microsoft.NETCore.App/10.0.3/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/lib64/dotnet/shared/Microsoft.NETCore.App/10.0.3/libSkiaSharp: cannot open shared object file: No such file or directory
/app/liblibSkiaSharp: cannot open shared object file: No such file or directory
/usr/lib64/dotnet/shared/Microsoft.NETCore.App/10.0.3/liblibSkiaSharp: cannot open shared object file: No such file or directory
   at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
   at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
   at SkiaSharp.SKImageInfo..cctor()
   --- End of inner exception stack trace ---
   at SkiaSharp.SKImageInfo..ctor(Int32 width, Int32 height)

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions