TypeInitializationException:The type initializer for 'Gdip' threw an exception

I’m building an application that runs on both windows and macos.

This application converts dng to bmp.

On Windows (10) it works but on MacOs I get:

TypeInitializationException:The type initializer for ‘Gdip’ threw an exception.

We’re using the latest AsposeImaging and the app is built in .net 6.

See code example:

@nielsbosma
The issue and recommended solution for NET6 is described here : Breaking change: System.Drawing.Common only supported on Windows - .NET | Microsoft Learn.

Following references may help as well:

This doesn’t work. I’ve tried:

  • Installing mono-libgdiplus
  • Adding the nugetpackage runtime.osx.10.10-x64.CoreCompat.System.Drawing
  • Adding a “runtimeconfig.template.json” file with:

{
“configProperties”: {
“System.Drawing.EnableUnixSupport”: true
}
}

@nielsbosma
Thank you for feedback. We’ve created internal ticket IMAGINGNET-5481 to investigate the issue from our side. It’s attached to the issue to let you see the progress.

Hi, I noticed in your latest release:

image.png (2.5 KB)

Does this mean that the issue is resolved?

@nielsbosma
As you may see in release notes IMAGINGNET-5481 is not resolved within current release.
In meantime you may evaluate NuGet Gallery | Aspose.Imaging 22.6.0-beta2, which does not require GDI+. Please pay attention that it’s still beta and has some known issues.

Any progress on when the GDI independent version is ready?

@nielsbosma
As you may see in release notes IMAGINGNET-5481 is not resolved within current release.
In meantime you may evaluate NuGet Gallery | Aspose.Imaging 22.6.0-beta2, which does not require GDI+. Please pay attention that it’s still beta and has some known issues.

@nielsbosma
Sorry for late reply, but we have the news on subject matter.

Following scenarios of Aspose.Imaging 23.3 installation was succeeded under

Mac OS Version: 12.1
OS Platform: Darwin
RID: osx.12-x64

  1. install NET6.0
    brew tap isen-ng/dotnet-sdk-versions
    brew install --cask dotnet-sdk6-0-400

  2. brew install mono-libgdiplus

  3. brew install p7zip (if not exists)

  4. download the example archive
    curl -L -o Aspose.Imaging.Example.zip “Dropbox - Aspose.Imaging.Example.Release.zip - Simplify your life

  5. extract the example from archive
    7z x Aspose.Imaging.Example.zip

  6. cd Release/net6.0

  7. run the example
    dotnet Aspose.Imaging.Example.dll

Example code is following :

using Aspose.Imaging;
using Aspose.Imaging.ImageOptions;

Console.WriteLine("About to convert jpg to png");

using(var image = Image.Load("shrek.jpg"))
{
    image.Save("shrek.png", new PngOptions());
}

Console.WriteLine("Conversion successful");

Full example sources.

I can’t expect my users to have brew and install mono-libgdplus. Is there any other way?

@nielsbosma
We’re completing preparation of release Aspose.Imaging for NET which uses Aspose.Drawing instead of System.Drawing.Common as graphics engine for NET7 configuration.
Than we’ll review installation requirements for MacOs and keep you updated.

Great! Looking forward to get this working for osx.

@nielsbosma
As we’ve released Aspose.Imaging .NET with Aspose.Drawing graphics engine for .NET7 following installation script for
Mac OS Version: 12.1
OS Platform: Darwin
RID: osx.12-x64
is applicable :

  1. download dotnet-install script
  2. install Net7.0 SDK
    ./dotnet-install.sh --channel 7.0 --runtime aspnetcore
  3. Download example archive
    curl -L -o Aspose.Imaging.Example.Net7.zip "https://www.dropbox.com/scl/fi/saog5q75rl2718px7v968/Aspose.Imaging.Example.Release.Net7.zip?rlkey=8r8rkzip6v2rmz55nplb3eg9j&dl=0"
  4. unzip archive
    7z x Aspose.Imaging.Example.Net7.zip
  5. run the example
    dotnet Aspose.Imaging.Example.dll

Full example code

Thank you for patience.

Much appreciated!

Is net 7.0 required?

Yes, above installation scenario requires Net7.

Do you have any plans to support net 6? I have 6.8% of my paying customers on win 8 and 9 and net 7 is not supported on those.

Aspose.Imaging .NET supports.NET6 and under the Windows installation should not cause specific issues. My previous answer was about MacOs installation scenario. You may also review NuGet Gallery | Aspose.Imaging 23.8.0 to see all supported platforms.

I have a quite complicated application structure where parts are divided into sepparate “plugins”. I need both windows and macos to be on the same .net version to not complicate things to much. So is there any chance to get this working on macos with net 6?

@nielsbosma
Understood. From our side we did not changed graphics engine for Net6 and lower configurations to avoid breaking change, which may affect other customers. So we’ve created internal ticket IMAGINGNET-6616 to launch separate nuget package Aspose.Imaging.Drawing, which will use Aspose.Drawing instead of System.Drawing.Common for netstandard2.0, net6.0 configuration. The package will not be included in the Aspose.Total so you’ll need to update the default reference to Aspose.Imaging to use it. Reference to the ticket is attached to this topic, so you’ll updated as it goes.