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

Free Support Forum - aspose.com

Getting TypeInitializationException for Gdip on Linux

I am attempting to run the Aspose.Total platform (v21.11.0) within a docker container on linux. I have references to the SkiaSharp.NativeAssets.Linux.NoDependencies (v2.80.3) library, as well as Microsoft.DotNet.PlatformAbstractions (v6.0.0) library.

My Dockerfile has the following:
RUN apt-get update && apt-get -f install && apt-get -y install libfontconfig1 libgdiplus
RUN cd /usr/lib && ln -s libgdiplus.so gdiplus.dll
RUN apt-get install -y --no-install-recommends libc6-dev
RUN export LD_LIBRARY_PATH=/usr/lib

as part of the deployment.

I am getting the following exception while running my code:
The type initializer for ‘Gdip’ threw an exception. System.TypeInitializationException: The type initializer for ‘Gdip’ threw an exception.
—> System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.
at System.Drawing.LibraryResolver.EnsureRegistered()
at System.Drawing.SafeNativeMethods.Gdip.PlatformInitialize()
at System.Drawing.SafeNativeMethods.Gdip…cctor()
— End of inner exception stack trace —
at System.Drawing.SafeNativeMethods.Gdip.GdipStringFormatGetGenericTypographic(IntPtr& format)
at System.Drawing.StringFormat.get_GenericTypographic()
at …ctor(Bitmap )
at …ctor(Int32 , Int32 , Single , Single , Boolean , Boolean , , SortedList2 ) at Aspose.Slides.Slide.(Boolean , , , SortedList2 , InterruptionToken )
at .(Presentation , Stream , Int32[] , PdfOptions , InterruptionToken )
at Aspose.Slides.Presentation.Save(Stream stream, SaveFormat format, ISaveOptions options)
at Aspose.Slides.Presentation.Save(Stream stream, SaveFormat format)

I am also getting the following exception I am unable to handle:
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter ‘buffer’)
at SkiaSharp.SKManagedStream.OnReadManagedStream(IntPtr buffer, IntPtr size)
at SkiaSharp.SKAbstractManagedStream.ReadInternal(IntPtr s, Void* context, Void* buffer, IntPtr size)

@ahazelwood,
Thank you for contacting support.

To investigate this case on our end, please share the following:

  • input presentation file
  • code example reproducing the error

The same is necessary for the second case that you described.

My apologies for not getting back to you sooner. I have created a test solution and docker deployment (running under a linux container). Publish the specified Project, and then in the deploy directory run: build && run

This should show you the kind of exceptions that I am getting which are unable to currently get handled. If I run the same executable under windows, it works fine.

Thanks.
Aspose.Test.zip (46.0 KB)

Here is one of the example runs:

C:\Users\ahazelwood.CIRADAR\source\repos\Aspose.Test\deploy>build && run

[+] Building 5.6s (12/12) FINISHED
=> [internal] load build definition from Dockerfile 0.2s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.2s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/runtime:6.0 0.0s
=> [1/7] FROM mcr.microsoft.com/dotnet/runtime:6.0 0.0s
=> [internal] load build context 0.2s
=> => transferring context: 400.75kB 0.1s
=> CACHED [2/7] RUN apt-get update && apt-get -f install && apt-get -y install apt-utils libfontconfig1 libgdiplus 0.0s
=> CACHED [3/7] RUN apt-get install -y libc6-dev 0.0s
=> CACHED [4/7] RUN cd /usr/lib && ln -s libgdiplus.so gdiplus.dll 0.0s
=> CACHED [5/7] RUN export LD_LIBRARY_PATH=/usr/lib 0.0s
=> CACHED [6/7] WORKDIR /app/bin 0.0s
=> [7/7] COPY ./bin /app/bin 3.9s
=> exporting to image 1.2s
=> => exporting layers 1.0s
=> => writing image sha256:c26f48393ea9a885b9749ba3c1be791a945d2974fc546cd31ccffb18c16c4dc7 0.1s
=> => naming to docker.io/library/aspose-test:4.5.5 0.0s
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app/bin
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter ‘buffer’)
at SkiaSharp.SKManagedStream.OnReadManagedStream(IntPtr buffer, IntPtr size)
at SkiaSharp.SKManagedStream.OnRead(IntPtr buffer, IntPtr size)
at SkiaSharp.SKAbstractManagedStream.ReadInternal(IntPtr s, Void* context, Void* buffer, IntPtr size)

@ahazelwood,
The TypeInitializationException mentioned in your first post is thrown when .NET 6 is installed on Linux. Unfortunately, Aspose.Slides for .NET does not support .NET 6 yet. Please try to use .NET 5.

Any idea on when .NET 6 will be supported? Also, it appears to work fine some of the time, the issue I’m mostly running into is the inability to capture the underlying Native Exception, the container simply exits out.

Thanks.

@ahazelwood,
I suppose this is the cause of your problems. I linked this forum thread to a corresponding issue with ID SLIDESNET-42778 in our tracking system. You will be notified when Aspose.Slides supports .NET 6 on Linux.

@ahazelwood,
I requested ETA for this issue from our development team. We will let you know soon.

Also, please don’t share license files on the forums in the future. I removed the Total license from your ZIP archive.

@ahazelwood,
Aspose.Slides for .NET will support .NET 6 on Linux not earlier than 2022’Q2.

Please note that TypeInitializationException error is also thrown if you use System.Drawing.Common 6.0.0. Please try to use the version 5.0.3.

At this time, the rest of our infrastructure is on the .NET 6, so it’s hard to move it back. The conversion part is running correctly under windows on .NET 6, so we’ll continue to support both (with a fallback on the windows side) for the time being. Let me know whenever .NET 6 is fully supported on Linux and I’ll be happy to let you know how it’s working.

Thanks.

@ahazelwood,
Thank you for the additional information. Our development team will do their best.