The type initializer for 'Gdip' threw an exception

Hi,

I am using the latest version of GroupDocs.Comparison for .NET in ASP.NET Core (ASPNET 8.0) application. The library works fine in Windows, however, I get error “The type initializer for ‘Gdip’ threw an exception.” when application is deployed to Linux based server via Docker container. Below is my docker file:

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
WORKDIR /app

# Set up APT sources manually
RUN echo "deb http://ftp.debian.org/debian bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
    echo "deb http://ftp.debian.org/debian bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
    echo "deb http://security.debian.org bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list

# Update package lists
RUN apt-get update --fix-missing

# Install required packages
RUN apt-get install -y apt-transport-https ca-certificates ffmpeg libgdiplus fontconfig fonts-liberation

# Update font cache
RUN fc-cache -f -v

COPY published/ ./
ENTRYPOINT ["dotnet", "document-comparison.dll"]

Problematic files that are compared are attached:
Tax Returns.pdf (107.5 KB)
Economy (2).pdf (640.6 KB)

Thanks.

@uax99
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): COMPARISONNET-4338

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like

Hello,

Any updates?

@uax99

This ticket is still under investigation. You’ll be notified in case of any update.

hi @uax99 ,
Thank you for your request.

Please make sure that your .csproj file contains the following entry:

<ItemGroup>
    <RuntimeHostConfigurationOption Include="System.Drawing.EnableUnixSupport" Value="true" />
</ItemGroup>

This will enable support for the System.Drawing.Common library on Linux (for more details, please refer to this Microsoft documentation).

Additionally, I would like to share a working Dockerfile for a .NET 8 Web API application with GroupDocs.Comparison, which properly configures the necessary dependencies for Linux:

# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080

# Add libgdiplus for graphics support
RUN apt-get update && apt-get install -y libgdiplus
RUN apt install software-properties-common -y
RUN echo "deb http://deb.debian.org/debian bookworm contrib non-free" > /etc/apt/sources.list.d/contrib.list
RUN apt update && apt upgrade
# Add fonts (required for GroupDocs.Comparison to use default Arial font in some scenarios)
RUN apt install ttf-mscorefonts-installer -y

# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["WebApplicationNet8/WebApplicationNet8.csproj", "WebApplicationNet8/"]
RUN dotnet restore "./WebApplicationNet8/WebApplicationNet8.csproj"
COPY . . 
WORKDIR "/src/WebApplicationNet8"
RUN dotnet build "./WebApplicationNet8.csproj" -c $BUILD_CONFIGURATION -o /app/build

# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./WebApplicationNet8.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish . 
ENTRYPOINT ["dotnet", "WebApplicationNet8.dll"]

Please note that ttf-mscorefonts-installer is required because GroupDocs.Comparison uses the default Arial font in some scenarios, and this package ensures that the necessary fonts are available for rendering.

Please try using this configuration and let me know if the issue persists.

1 Like