Aspose.Slides Throws an Exception When Attempting to Clone a Slide

Hi, I’m getting the following error when running an application using Aspose.Slides in a Alpine linux container. I’ve tried upgrading to 25.10, but the issue still persists. It occurs when the code attempts to clone a slide and we receive the following error:

System.TypeInitializationException: The type initializer for 'Windows.Win32.PInvoke' threw an exception.
2025-11-04 16:40:23.124 |      ---> System.TypeInitializationException: The type initializer for 'System.Drawing.Gdip' threw an exception.
2025-11-04 16:40:23.124 |      ---> System.TypeInitializationException: The type initializer for 'Windows.Win32.Graphics.GdiPlus.GdiPlusInitialization' threw an exception.
2025-11-04 16:40:23.124 |      ---> System.DllNotFoundException: Unable to load shared library 'gdiplus.dll' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: 
2025-11-04 16:40:23.124 |     Error loading shared library /app/gdiplus.dll.so: No such file or directory
2025-11-04 16:40:23.124 |     Error loading shared library /usr/share/dotnet/shared/Microsoft.NETCore.App/9.0.10/gdiplus.dll.so: No such file or directory
2025-11-04 16:40:23.124 |     Error loading shared library gdiplus.dll.so: No such file or directory
2025-11-04 16:40:23.124 |     Error loading shared library /app/libgdiplus.dll.so: No such file or directory
2025-11-04 16:40:23.124 |     Error loading shared library /usr/share/dotnet/shared/Microsoft.NETCore.App/9.0.10/libgdiplus.dll.so: No such file or directory
2025-11-04 16:40:23.124 |     Error loading shared library libgdiplus.dll.so: No such file or directory
2025-11-04 16:40:23.124 |     Error loading shared library /app/gdiplus.dll: No such file or directory
2025-11-04 16:40:23.124 |     Error loading shared library /usr/share/dotnet/shared/Microsoft.NETCore.App/9.0.10/gdiplus.dll: No such file or directory
2025-11-04 16:40:23.124 |     Error loading shared library gdiplus.dll: No such file or directory
2025-11-04 16:40:23.124 |     Error loading shared library /app/libgdiplus.dll: No such file or directory
2025-11-04 16:40:23.124 |     Error loading shared library /usr/share/dotnet/shared/Microsoft.NETCore.App/9.0.10/libgdiplus.dll: No such file or directory
2025-11-04 16:40:23.124 |     Error loading shared library libgdiplus.dll: No such file or directory
2025-11-04 16:40:23.124 |     
2025-11-04 16:40:23.124 |        at Windows.Win32.PInvokeCore.GdiplusStartup(UIntPtr* token, GdiplusStartupInput* input, GdiplusStartupOutput* output)
2025-11-04 16:40:23.124 |        at Windows.Win32.PInvokeCore.GdiplusStartup(UIntPtr* token, GdiplusStartupInput* input, GdiplusStartupOutput* output)
2025-11-04 16:40:23.124 |        at Windows.Win32.Graphics.GdiPlus.GdiPlusInitialization.Init()
2025-11-04 16:40:23.124 |        at Windows.Win32.Graphics.GdiPlus.GdiPlusInitialization..cctor()
2025-11-04 16:40:23.124 |        --- End of inner exception stack trace ---
2025-11-04 16:40:23.124 |        at Windows.Win32.Graphics.GdiPlus.GdiPlusInitialization.EnsureInitialized()
2025-11-04 16:40:23.124 |        at System.Drawing.Gdip.Init()
2025-11-04 16:40:23.124 |        at System.Drawing.Gdip..cctor()
2025-11-04 16:40:23.124 |        --- End of inner exception stack trace ---
2025-11-04 16:40:23.124 |        at System.Drawing.Gdip.get_Initialized()
2025-11-04 16:40:23.124 |        at Windows.Win32.PInvoke..cctor()
2025-11-04 16:40:23.124 |        --- End of inner exception stack trace ---
2025-11-04 16:40:23.124 |        at Windows.Win32.PInvoke.GdipCreateFontFamilyFromName(PCWSTR name, GpFontCollection* fontCollection, GpFontFamily** fontFamily)
2025-11-04 16:40:23.124 |        at Windows.Win32.PInvoke.GdipCreateFontFamilyFromName(PCWSTR name, GpFontCollection* fontCollection, GpFontFamily** fontFamily)
2025-11-04 16:40:23.124 |        at System.Drawing.FontFamily.CreateFontFamily(String name, FontCollection fontCollection)
2025-11-04 16:40:23.124 |        at .(String , String&)
2025-11-04 16:40:23.124 |        at .(String , FontStyle, Boolean )
2025-11-04 16:40:23.124 |        at .(String , FontStyle)
2025-11-04 16:40:23.124 |        at.( , Boolean)
2025-11-04 16:40:23.124 |        at.( , Boolean, Single , ␛ , Int32 , Boolean )
2025-11-04 16:40:23.124 |        at .( , String, ␛ , Int32 , Single , FontStyle , Boolean )
2025-11-04 16:40:23.124 |        at .(String , ␛, Int32 , Single , FontStyle , Boolean )
2025-11-04 16:40:23.124 |        at .(String , ␛, Int32 , Single , FontStyle , Boolean )
2025-11-04 16:40:23.124 |        at ␛.(String , ␛, Int32 , Single , FontStyle , Boolean )
2025-11-04 16:40:23.124 |        at .()
2025-11-04 16:40:23.124 |        at .(& , Boolean&)
2025-11-04 16:40:23.124 |        at ␛.()
2025-11-04 16:40:23.124 |        at ␛..ctor(TextFrame , , IBaseSlide ,  , [] )
2025-11-04 16:40:23.124 |        at .( , )
2025-11-04 16:40:23.124 |        at.( , Single, Single ,  )
2025-11-04 16:40:23.124 |        at.( , &, RectangleF& ,  )
2025-11-04 16:40:23.124 |        at.( , ShapeFrame&, RectangleF& ,  )
2025-11-04 16:40:23.124 |        at .(IAutoShape , ,  , ␛ )
2025-11-04 16:40:23.124 |        at .(IGroupShape , ,  , ␛ )
2025-11-04 16:40:23.124 |        at.(IBaseSlide , ,  )
2025-11-04 16:40:23.124 |        at ␛.(IMasterSlide , Boolean)
2025-11-04 16:40:23.124 |        at .(␛ , IMasterSlide, Boolean ,  )
2025-11-04 16:40:23.124 |        at.(IPresentation , IMasterSlide, Boolean )
2025-11-04 16:40:23.124 |        at Aspose.Slides.MasterSlideCollection.(MasterSlide , Boolean)
2025-11-04 16:40:23.124 |        at Aspose.Slides.MasterSlideCollection.(IMasterSlide , Boolean)
2025-11-04 16:40:23.124 |        at Aspose.Slides.SlideCollection.AddClone(ISlide sourceSlide)

I’ve already tried installing libgdiplus using ’ apk add’, but it’s possible that the project or container are missing something.

@a.mitsov

Summary
Aspose.Slides for .NET relies on System.Drawing (GDI+) for some internal work such as font handling. In an Alpine‑Linux container the native GDI+ library (libgdiplus) is missing, so the runtime throws a DllNotFoundException when you call SlideCollection.AddClone.

Why it happens

  • System.Drawing.Common on Linux is a thin wrapper around the native libgdiplus library.
  • The default Alpine image does not contain libgdiplus (or the basic TrueType fonts it needs).
  • When Aspose.Slides touches GDI+ code, the missing native library causes the initialization of System.Drawing.Gdip to fail, which propagates up to the slide‑clone operation.
  • Updating the Aspose.Slides NuGet package does not add the native dependency; you must provide it yourself or switch to a fully managed Aspose.Slides variant that does not depend on GDI+.

What to do next

  1. Install the required native libraries in the container
# Dockerfile – Alpine base
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS base
WORKDIR

# Install libgdiplus and a minimal set of TrueType fonts
RUN apk add --no-cache libgdiplus fontconfig ttf-dejavu

# Ensure the loader can find the library (usually not needed on Alpine)
ENV LD_LIBRARY_PATH=/usr/lib

If you are using a Debian‑based image, the equivalent command is:

apt-get update && apt-get install -y libgdiplus fonts-dejavu-core
  1. Confirm that at least one TrueType font is available
fc-list | grep -i dejavu # should list DejaVu fonts
  1. Run your code again – the clone operation should now succeed:
using Aspose.Slides;

using (Presentation pres = new Presentation("input.pptx"))
{
ISlide source = pres.Slides[0];
pres.Slides.AddClone(source); clone works after libgdiplus is present
pres.Save("output.pptx", SaveFormat.Pptx);
}
  1. Optional: use a fully cross‑platform package

If you prefer to avoid any native dependencies, replace the standard package with the managed alternative:

dotnet remove package Aspose.Slides
dotnet add package Aspose.Slides.Drawing

Aspose.Slides.Drawing implements the same core functionality without relying on System.Drawing or libgdiplus, so the same code can run on Alpine without the extra native libraries.

  1. If the issue remains
  • Run strace -f -e openat ./YourApp inside the container to identify any missing shared objects.
  • Verify that LD_LIBRARY_PATH includes the directory where libgdiplus.so resides (typically /usr/lib).
  • Check the container logs for additional “font not found” warnings and install any missing font packages accordingly.

Next steps – Installing libgdiplus (and a basic TrueType font package) resolves the current DllNotFoundException. Switching to Aspose.Slides.Drawing provides a future‑proof, fully managed solution that eliminates the native GDI+ requirement on Linux containers.

This hasn’t been very helpful. I tried installing libgdiplus, but to no avail. Also, the package Aspose.Slides.Drawing doesn’t exist. Is there another way to resolve this issue?

@a.mitsov,
Thank you for contacting free support. Please note the following:

  • Aspose.Slides for .NET requires GLIBC 2.23 or newer on Linux systems.
  • When running on non-Windows systems, your application must include the following line at startup:
      AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true);

More details:
System Requirements|Aspose.Slides Documentation