We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

.NET 6 in Docker

The project I’m working on is a .NET 6.0 and using the Aspose.Words to convert Docx files to PDF. It is working fine if I run it on Windows 10 directly but having issues with embedded images when run under Docker, both on Linux and Windows.

Based on the documentation, it requires quite older version of operating systems which are 2-3 versions late for the currently available versions of .NET 6.0? What are my options for this if I want to run it using .NET 6.0 while in the Docker environment? Are there ways to make it work with the default images for .NET 6.0? Thanks!

@vdolosa Most likely, you have missed to add reference to SkiaSharp.NativeAssets.Linux. In this case images will not be rendered under Linux. Aspose.Words for .NET Standard uses SkiaSharp to deal with graphics, to make it work on Linux you have to add reference either to SkiaSharp.NativeAssets.Linux or to SkiaSharp.NativeAssets.Linux.NoDependencies

If you add reference to SkiaSharp.NativeAssets.Linux, you should also install libfontconfig1 in your system. SkiaSharp.NativeAssets.Linux depends on this library. You can use the following command to install it:

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

If you do not have rights to install packages, or other reasons not to install libfontconfig1, you can simply use SkiaSharp.NativeAssets.Linux.NoDependencies, which does not require installation of libfontconfig1.

I have tested with a simple console project with .NET 6.0 official image. Here is my docker file:

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

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"]

In my .csproj file I have the following:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

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

</Project>

and the following simple code:

License lic = new License();
lic.SetLicense("/temp/Aspose.Words.NET.lic");

Document document = new Document("/temp/in.docx");
document.Save(@"/temp/out_linux.pdf");

The example is run using the following two commands:

docker build -t awtest .
docker run --mount type=bind,source=C:\Temp,target=/temp --rm awtest from Docker

Regarding Windows images. SkiaSharp does not work properly on Windows Nano Server because of know limitation. https://github.com/mono/SkiaSharp/issues/1105
However, you can use Windows Server Core images without any limitations.

1 Like