Unable to load images in linux

Hi ,

we are unable to load images when we run aspose on docker container.

we added these references in the csproj file

<PackageReference Include="SkiaSharp" Version="2.80.2" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.2" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.2" />

and this is part of our dockerfile

RUN apk update && apk upgrade

RUN apk add --no-cache freetype-dev

RUN apk add --no-cache fontconfig

RUN apk --no-cache add msttcorefonts-installer fontconfig && \
    update-ms-fonts && \
    fc-cache -f

COPY --from=builder randomlocation/netcoreapp3.1/publish app

WORKDIR app

RUN wget -q https://github.com/mono/SkiaSharp/releases/download/v1.60.3/libSkiaSharp.so

RUN chmod -x libSkiaSharp.so

Are we missing anything?

@randomuser123

  1. It is not required to add both SkiaSharp.NativeAssets.Linux and SkiaSharp.NativeAssets.Linux.NoDependencies packages. It is enough to add one.

  2. Could you please specify what base image you use?

For your reference here is a simple Dokerfile configuration, that works fine on my side:

FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base

WORKDIR /app

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

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["TestNet6.csproj", "."]
RUN dotnet restore "./TestNet6.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "TestNet5.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "TestNet6.csproj" -c Release -r linux-x64 --no-self-contained -o /app/publish

FROM base AS final

WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestNet6.dll"]

Here is Dependencies list in the .csproj:

<PackageReference Include="Aspose.Words" Version="23.3.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.3" />

Hi alexey,

we tried without this SkiaSharp.NativeAssets.Linux.NoDependencies too

base image is dotnet-sdk:3.1-alpine

hi alexey,

one more thing we found is that the dll for skiasharp is missing.

@randomuser123 Here is my working Dokerfile for Alpine Linux:

FROM mcr.microsoft.com/dotnet/runtime:6.0-alpine3.15 AS base
WORKDIR /app

# Required to make SkiaSharp 2.80.1 work. If use 2.80.3 SkiaSharp.NativeAssets.Linux.NoDependencies it is not required.
#RUN apk add --no-cache fontconfig
# Requred to make code works on 6.0-alpine3.15. See https://docs.microsoft.com/en-us/answers/questions/728280/running-net-6-project-in-docker-throws-globalizati.html
RUN apk add --no-cache icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib
# For debug purposes.
RUN apk add --no-cache bash
# Add the missed ld-linux-x86-64.so.2 dependency.
RUN apk add --no-cache gcompat

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["TestNet6.csproj", "."]
RUN dotnet restore "./TestNet6.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "TestNet6.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "TestNet6.csproj" -c Release -r linux-x64 --no-self-contained -o /app/publish

FROM base AS final

WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestNet6.dll"]

hi alexey,

unfortunately that didnt work either. we use .net3.1… could this be the issue?

adding this package RUN apk add --no-cache gcompat is causing our kubernetes pods to go down

@randomuser123 I have retested with 3.1-alpine base container and everything works fine on my side. Here is my test Dockerfile:

FROM mcr.microsoft.com/dotnet/runtime:3.1-alpine AS base

WORKDIR /app

# Required to make SkiaSharp 2.80.1 work. If use 2.80.3 SkiaSharp.NativeAssets.Linux.NoDependencies it is not required.
RUN apk add --no-cache fontconfig
# Requred to make code works on 6.0-alpine3.15. See https://docs.microsoft.com/en-us/answers/questions/728280/running-net-6-project-in-docker-throws-globalizati.html
RUN apk add --no-cache icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib
# Add the missed ld-linux-x86-64.so.2 dependency.
RUN apk add --no-cache gcompat

FROM mcr.microsoft.com/dotnet/sdk:3.1-alpine AS build
WORKDIR /src
COPY ["TestNetCore.csproj", "."]
RUN dotnet restore "./TestNetCore.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "TestNetCore.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "TestNetCore.csproj" -c Release -r linux-x64 --no-self-contained -o /app/publish

FROM base AS final

WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestNetCore.dll"]

Here is my .csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>
  
   <PropertyGroup>
     <InvariantGlobalization>false</InvariantGlobalization>
   </PropertyGroup>

  <ItemGroup>
	  <PackageReference Include="Aspose.Words" Version="23.3.0" />
	  <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.3" />
  </ItemGroup>

</Project>

Code for testing is pretty simple, open document and save it as PDF.

Document doc = new Document(@"/temp/in.docx");
doc.Save(@"/temp/out.pdf");

Images in output PDF are properly rendered.

Hi alexey,

i tried what you gave us, the api gives this error

Code Details
Undocumented TypeError: Failed to fetch

this is our docker file:

FROM companyartifactory/dotnet-sdk:3.1-alpine AS builder

COPY . src

WORKDIR src

RUN dotnet restore  -s http://nuget.company.com/test/nuget/ -s https://api.nuget.org/v3/index.json -v d

RUN dotnet restore

RUN dotnet publish -c Release -f netcoreapp3.1

FROM companyartifactory/dotnet-runtime:3.1-alpine

RUN apk update && apk upgrade

RUN apk add --no-cache icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib

RUN apk add --no-cache fontconfig

RUN apk add --no-cache gcompat

COPY --from=builder src/src/Api/bin/Release/netcoreapp3.1/publish app

WORKDIR app

EXPOSE 5001

ENTRYPOINT ["dotnet", "Api.dll"]

@randomuser123 Unfortunately, I cannot reproduce the problem on my side. Please try running the attached test project on your side and let us know whether it works on your side: TestNetCore.zip (2.1 KB)

This is a simple console application and minimum Dokerfile I have used for testing.

Hi alexey,

the src application folder has 5 .csproj folders. and the docker file is in the parent folder

structure is like this

do you know if this could be the issue? i am new to docker so just doing trial and error

and the references to skiasharp are in the repository.csproj

@randomuser123 Unfortunately, I am also not a professional in docker configuration. But I do not think the project structure matters. Here is a simple test with project structure similar to yours: TestNested.zip and it works fine on my side.

hi alexey,

thanks for your help, we upgraded to .net6 and debian based image, and this resolved our issue. for fonts we used noto fonts.

1 Like