Aspose.PDF exception SvgImage when adding a bitmap image

Just upgraded Aspose.PDF .NET from version 22.9.0 to version 25.12.0.
Now I am getting this exception in about 25% of the calls.
Invalid image stream (Could not load type ‘Aspose.Imaging.FileFormats.Svg.SvgImage’ from assembly ‘Aspose.Imaging, Version=25.12.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56’.)

This happens at this callstack:
System.ArgumentException:
at Aspose.Pdf.XImageCollection.#=z0FVcSxdmyLz0GzSF_Q== (Aspose.PDF, Version=25.12.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at Aspose.Pdf.XImageCollection.#=zfGyY84wOq1Qv (Aspose.PDF, Version=25.12.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at Aspose.Pdf.XImageCollection.#=zubr$9aQ= (Aspose.PDF, Version=25.12.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at Aspose.Pdf.XImageCollection.Add (Aspose.PDF, Version=25.12.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56)
at SalesforceFunctions.Functions.Delegated.MySign.MySignSignFunction.PutSignature (SalesforceFunctions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: D:\agent2_work\232\s\SalesforceFunctions\Functions\Delegated\MySign\MySignSignFunction.cs:123)

I am adding a bitmap image here to the PDF.
In the previous version there was no problem.
Now it is complaining about Aspose.Imaging. From documentation it seems Aspose.PDF should not have a dependeny on Aspose.Imaging. So that is strange.
And we are not using svg at all, so that makes it even more strange.

Any idea what the problem can be?

@dev3rdparties_mysolution

You’re encountering an exception after upgrading Aspose.PDF .NET from version 22.9.0 to 25.12.0, specifically related to a missing Aspose.Imaging.FileFormats.Svg.SvgImage type when adding a bitmap image . This suggests that Aspose.PDF might be indirectly relying on Aspose.Imaging for image processing, even if not explicitly documented as a dependency .

The error could stem from version incompatibilities or missing dependencies in the Aspose.Imaging library between these versions, especially when handling certain image types such as bitmaps . There is also a known scenario where Aspose.PDF fails to load Aspose.Imaging when deployed in the Global Assembly Cache (GAC), which may point to assembly loading issues .

To resolve this:

  1. Ensure that the correct version of Aspose.Imaging is installed and compatible with Aspose.PDF 25.12.0.
  2. Verify that all required Aspose.Imaging assemblies are correctly deployed with your application and not loaded from the GAC .
  3. Consider testing with a clean deployment of both libraries to rule out any caching or version conflicts.

If the issue persists after verifying these points, it may be a bug introduced in the newer version of Aspose.PDF or Aspose.Imaging, and further investigation or a fix from Aspose support would be necessary.

A support engineer will follow up in this thread if needed.

NuGet Gallery | Aspose.PDF 26.1.0 does not state Aspose.Imaging as an dependency. Also, you want to use Apose.Imaging explicitly, you whould need a license for it.

How does this work? Is Apose.Imaging dll embedded in the Aspose.PDF.
Could it perhaps be that there is going something wrong with loading that embedded assembly?

I am also using Aspose.Words in the same application, but that seems not to use Aspose.Imaging.
Else perhaps there could be a version conflict, depending on which version is loaded first?

Some more information: I am running this application in Azure Functions isolated worker model.
I found some hints on internet that using the correct AssemblyLoadContext could be important when loading assemblies runtime. No idea how it is used by Aspose.PDF. But perhaps this as an hint?

@dev3rdparties_mysolution

If possible, can you please provide some sample code snippet with sample files and steps to reproduce this issue in our environment? We will try to replicate it and address it accordingly.

Yes, I would like to do that. But where can I upload files? I don’t see an option for that in this chat.
Also I can’t yet reproduce it locally or in test environment.

@dev3rdparties_mysolution

You can upload files using the upload button in the post editor.
image.png (34.0 KB)

If files are larger than 10MB, you can upload to Google Drive or Dropbox and share the link with us.

Ow, but that complaince that it should be an image.
But anyway: here is a link.
It shows the code I use. I am trying to reproduce it in our test environment, but was not able to do that. As I said, my application runs in Azure Functions Isolated worker model.
Could it perhaps have something to do with AssemblyLoadContext that sometimes the Aspose.Imaging types can not be found?

@dev3rdparties_mysolution

Could it perhaps have something to do with AssemblyLoadContext that sometimes the Aspose.Imaging types can not be found?

We cannot say for sure as we first need to investigate this issue in details. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-61598

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.