.NET Conversion from RTF/DOCX to PDF exception inside Docker on Alpine Linux

Works fine locally. Issue happens in docker container running on Alpine Linux.

GroupDocs.Conversion: v22.12

.NET version: .NET 7.0

Error Message:
GroupDocs.Conversion.Exceptions.GroupDocsConversionException: Object reference not set to an instance of an object. at d.() at GroupDocs.Conversion.Converter.() at GroupDocs.Conversion.Converter.Convert(SaveDocumentStream document, ConvertedDocumentStream documentCompleted, ConvertOptions convertOptions)

Sample Code: result.Content is a base64 string

            using (var inputStream = new MemoryStream(result.Content))
            {
                using (var outputStream = new MemoryStream())
                {
                    using (Converter converter = new Converter(() => inputStream))
                    {
                        PdfConvertOptions options = new PdfConvertOptions();
                        converter.Convert(() => outputStream, (convertedStream, sourceName) =>
                        {
                            result.Content = outputStream.ToArray();

                        }, options);
                    }

                    result.MimeType = "application/pdf";
                }
            }
1 Like

@smauro

Could you please share the running/sample application with docker image and source file? We’ll then investigate this scenario at our end.

WebApplication1.zip (174.0 KB)

Hi @Atir_Tahir, please see attached. Thank you.

1 Like

@smauro

We are investigating this scenario. Your investigation ticket ID is CONVERSIONNET-5731. You’ll be notified in case of any update.

1 Like

Hi Atir_Tahir,

Do we have any updates / resolution for smauro’s above issue?
We are in the same team and this is becoming urgent for us and our customer.
We would like to make sure this works for us before we purchase the license.

Regards,
Duncan McIntyre

@dmcintyreiqx

We are still investigating this ticket. We’ll let you know if any further details/information is required.

@smauro, @dmcintyreiqx

Please take a look at this documentation article - How to build in docker.
We’ve modified your docker file, please download.zip (612 Bytes) it and observe the changes.
Document Conversion is working after that modification. The only change is addition of the following lines:

RUN apt-get update && apt-get install -y ffmpeg libgdiplus

RUN sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list
RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig
RUN fc-cache -f -v

Hi @Atir_Tahir,

We are using an alpine linux image as the base and not debian. The equivalent commands we used are as follows:

FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build

RUN apk add --no-cache ffmpeg libgdiplus

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

But we don’t have the equivalent for “sed”
RUN sed -i’.bak’ ‘s/$/ contrib/’ /etc/apt/sources.list

Do you think this is sufficient? Please advise. Thank you.

@smauro

We edited the Docker file with the following configuration the conversion is working:

FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine AS base
WORKDIR /app
EXPOSE 80
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

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

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

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

FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine AS runtime

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]

Following are the libraries and environment settings which must be added in Docker file:

ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

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

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

Hi @Atir_Tahir,

We tried converting xlsx and ppt files but got errors. We’re using Alpine but we’ve tried it in Debian as well. Same error. Test_File.zip (226.9 KB)

@smauro

Could you please share a screencast/short video of this issue? Please elaborate all steps (from very start) using that issue could be reproduced.

HI @Atir_Tahir,

I have attached the sample project to show the sample conversions. WebApplication1.zip (746.7 KB)

Hi @Atir_Tahir Here’s the project Alpine Linux. WebApplication1.zip (783.2 KB)

@smauro

Thanks for the details. We’ll investigate it and let you know in case of any update.

1 Like

Hi @Atir_Tahir,

Sorry to ask but do you have an update? Thank you.

@smauro

I am afraid but the ticket is still in progress.

@smauro

You need to create runtimeconfig.template.json next to your csproj file with the following content:

{
    "configProperties": {
        "System.Drawing.EnableUnixSupport": true
    }
}

Take a look at this sample.zip (773.9 KB) application.

1 Like

Hi @Atir_Tahir,

It’s working now. Thank you so much!

1 Like

Hi @Atir_Tahir,

By the way, we have tested it in Windows nano based docker container. We’re getting null exception. I have attached the docker file. Thank you.Dockerfile_win.zip (406 Bytes)

@smauro

We are investigating this scenario.

1 Like