Remote images not working in Docker

Based on your example Create Word (DOCX) or PDF in Docker container I am trying to add an image from a remote source likeso

document.Content.End.InsertRange(new Picture(document, "https://picsum.photos/200/300", isLink: true).Content);

yet I get an error (see below). I found that changing from

SkiaSharp.NativeAssets.Linux to
SkiaSharp.NativeAssets.Linux.NoDependencies

will solve the problem, but I am not experienced enough with Linux to determine whether that’s a good solution or whether it could have undesirable consequences. I also tried

RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev

in the dockerfile, which mitigated the error but lead to images often being shown faulty (also shown below)

I set up a minimal example: GitHub - sdw-ps/gembox-docker: minimal project to demonstrate problems with remote images

I tried this fix for version 35.0.1443, it will not work with 33.x


Error:

    System.InvalidOperationException: 'Bitmap decoding failed. 'WPF' (https://docs.microsoft.com/en-us/dotnet/desktop/wpf/) was not found on the system. If the platform on which the application is running supports 'WPF', make sure that your project uses it. 'System.Drawing' (https://docs.microsoft.com/en-us/dotnet/api/system.drawing) was not found on the system. If the platform on which the application is running supports 'System.Drawing', make sure that your project uses it. 'SkiaSharp' threw an exception of type 'System.TypeInitializationException' and with message 'The type initializer for 'SkiaSharp.SKData' threw an exception.'. For more details about the exception, see the inner exception. 'ImageSharp' (https://github.com/SixLabors/ImageSharp/) was not found on the system. If the platform on which the application is running supports 'ImageSharp', make sure that your project uses it. 'GemBox' threw an exception of type 'System.NotSupportedException' and with message 'Specified method is not supported.'.'

    Inner Exceptions:
    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.10/libSkiaSharp.so: cannot open shared object file: No such file or directory
    /app/bin/Debug/net7.0/libSkiaSharp.so: cannot open shared object file: No such file or directory
    /app/bin/Debug/net7.0/runtimes/linux-x64/native/liblibSkiaSharp.so: cannot open shared object file: No such file or directory
    /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.10/liblibSkiaSharp.so: cannot open shared object file: No such file or directory
    /app/bin/Debug/net7.0/liblibSkiaSharp.so: cannot open shared object file: No such file or directory
    /app/bin/Debug/net7.0/runtimes/linux-x64/native/libSkiaSharp: cannot open shared object file: No such file or directory
    /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.10/libSkiaSharp: cannot open shared object file: No such file or directory
    /app/bin/Debug/net7.0/libSkiaSharp: cannot open shared object file: No such file or directory
    /app/bin/Debug/net7.0/runtimes/linux-x64/native/liblibSkiaSharp: cannot open shared object file: No such file or directory
    /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.10/liblibSkiaSharp: cannot open shared object file: No such file or directory
    /app/bin/Debug/net7.0/liblibSkiaSharp: cannot open shared object file: No such file or directory

image

Hi,

Please try using this instead in your Dockerfile:

RUN apt-get install -y fontconfig

Does this solve your issue?

Regards,
Mario

I tried that version as well. The error is still present. I updated the minimal example to use fontconfig.

I’ve used the same Dockerfile as you and I installed SkiaSharp.NativeAssets.Linux (not SkiaSharp.NativeAssets.Linux.NoDependencies).

The following is a screenshot of the resulting DOCX file that I get:

So unfortunately, I was unable to reproduce your issue.
Nevertheless, you mentioned that it worked for you when using SkiaSharp.NativeAssets.Linux.NoDependencies so perhaps that is currently the best option here.

Last, regarding this package installation:
RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev
I believe you were missing the libfontconfig1 package.

I hope this helps.

Regards,
Mario

Hm, so it works on your machine. That is the kind of problem that docker promised to solve ¯_(ツ)_/¯

Thanks for testing the min example, I will go with the NoDependencies solution then.