barnhill / barcodelib

C# Barcode Image Generation Library
Apache License 2.0
736 stars 239 forks source link

BarcodeLib version 3.0.0 not working docker linux #163

Closed dorathoto closed 1 year ago

dorathoto commented 1 year ago

_An unhandled exception occurred while processing the request. 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: /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.11/libSkiaSharp.so: cannot open shared object file: No such file or directory /app/libSkiaSharp.so: cannot open shared object file: No such file or directory /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.11/liblibSkiaSharp.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.11/libSkiaSharp: 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.11/liblibSkiaSharp: cannot open shared object file: No such file or directory /app/liblibSkiaSharp: cannot open shared object file: No such file or directory SkiaSharp.SkiaApi.sk_color4f_fromcolor(uint color, SKColorF* color4f)

ASP.NET 7 Docker image: mcr.microsoft.com/dotnet/aspnet:7.0 Windows: ok it works Linux (Debian): not I can't test with other images, e.g. ubuntu

My code:

            BarcodeStandard.Barcode barcode = new BarcodeStandard.Barcode();
            barcode.IncludeLabel = false;
            barcode.EncodedType = BarcodeStandard.Type.Code128;
            barcode.Encode(BarcodeStandard.Type.Code128, data);
            barcode.SaveImage(path, BarcodeStandard.SaveTypes.Png);

I believe I will have to create an intermediate image by adding something like: sudo apt-get install -y libfontconfig1

or try to use the package SkiaSharp.NativeAssets.Linux.NoDependencies

as per: https://github.com/mono/SkiaSharp/issues/1341

updated

when trying to mount a custom image:

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS final-stage
RUN apt-get update && apt-get install -y --no-install-recommends fontconfig libfontconfig1
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get install -y tzdata

It didn't help, same error.

dorathoto commented 1 year ago

It worked! putting SkiaSharp.NativeAssets.Linux.NoDependencies in the project stopped the problem.

I'm going to make a PR

barnhill commented 1 year ago

This PR has been merged and should be out in 3.0.1 which has been uploaded to Nuget

barnhill commented 1 year ago

Fixed by https://github.com/barnhill/barcodelib/pull/164