Aspose PDF error: ‘Gdip’ threw an exception with Dotnet Core 3.x app on Mac OSX

3.8k Views Asked by At

I am running a Dotnet core app (3.1) on a Mac (Catalina) and I’m trying to add an image to a PDF using Aspose PDF with this tutorial: https://docs.aspose.com/pdf/net/manipulate-images/.

I get an error when trying to add the imageStream.

"Invalid image stream (The type initializer for ‘Gdip’ threw an exception.)’.

var logoFile = "logo.jpg";
FileStream imageStream = new FileStream(logoFile, FileMode.Open, FileAccess.Read);
page.Resources.Images.Add(imageStream); //Error on this line

Doing my research, this appears to be related to needing the libgdiplus library. I installed this with brew install mono-libgdiplus but I am still getting this error.

Sample Project that can replicate the issue: https://github.com/duyn9uyen/aspose-add-image-to-pdf.

Aspose.Pdf: Version=“20.3.0”.

Can someone help?

1

There are 1 best solutions below

1
On BEST ANSWER
  1. Need to install libgdiplus. https://learn.microsoft.com/en-us/dotnet/core/install/macos

    brew update 
    brew install mono-libgdiplus
    
  2. Need to install CoreCompat.System.Drawing from https://github.com/CoreCompat/CoreCompatdotnet. Add this package reference, runtime.osx.10.10-x64.CoreCompat.System.Drawing --version 5.8.64 in your .csproj file.

    <PackageReference Include="runtime.osx.10.10-x64.CoreCompat.System.Drawing" Version="5.8.64" />