This documentation addresses common errors encountered when using Aspose.Words for document conversion (e.g., to PDF, JPEG, PNG) in a .NET Core 2.0 application running inside a Docker container. The errors typically relate to SkiaSharp type initializers and occur only in Docker environments (not in local IIS Express).
The type initializer for ‘SkiaSharp.SKManagedStream’ threw an exception.
The type initializer for ‘SkiaSharp.SKImageInfo’ threw an exception.
The errors stem from missing native dependencies required by the SkiaSharp library, which Aspose.Words uses for rendering graphics. Docker containers (especially lightweight Linux-based images) often lack these dependencies by default.
Add the necessary native libraries to your Docker image. These include:
Update your Dockerfile to include these dependencies:
# Use a .NET Core 2.0 compatible base image
FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build-env
# Install dependencies
RUN apt-get update && \
apt-get install -y \
libfontconfig1 \
libgdiplus \
libc6-dev \
&& rm -rf /var/lib/apt/lists/*
# Rest of your Dockerfile (build steps, entrypoint, etc.)
Ensure the SkiaSharp.NativeAssets.Linux NuGet package is installed in your project. This package provides Linux-specific binaries required for SkiaSharp to work in Docker.
dotnet add package SkiaSharp.NativeAssets.Linux –version 2.88.0
Note: Use a version compatible with your project and Aspose.Words.
Avoid using minimal Docker images (e.g., alpine), as they lack essential dependencies. Use a Debian/Ubuntu-based image instead:
FROM mcr.microsoft.com/dotnet/core/sdk:2.1-bionic
Ensure you’re using the latest compatible versions of:
Check for version conflicts in your .csproj file.
If fonts are missing (common in headless Docker environments), explicitly install fonts or copy them to the container:
# Example: Install DejaVu fonts
RUN apt-get install -y ttf-dejavu
Run the Docker container in debug mode to capture detailed error logs:
docker run -it --rm your-image-name
docker build --no-cache -t your-image-name
If the issue persists, contact Aspose Support with your Dockerfile, error logs, and a reproducible sample.
Work with our skilled .Net developers to accelerate your project and boost its performance.
Hire .Net Developers