System.MissingMethodException in Aspose.pdf - nuget package 25.5.0 - targeting .NET Framework 4.8

Was able to narrow this down to a small block of code:

Using oFS As New IO.FileStream(path:=sPageImage, mode:=IO.FileMode.Create)
    oPage.Resources.Images.Item(1).Save(stream:=oFS,
                                        format:=Drawing.Imaging.ImageFormat.Jpeg)
    oFS.Close()
End Using

result: system.missingmethodexception
Method not found: Void Aspose.Pdf.XImage.Save(System.IO.Stream, System.Drawing.Imaging.ImageFormat)

The weirdest thing about it is that it doesn’t even seem necessary for the code to try and hit those statements. Them simply being there is enough to trigger it.

Okay I have to admit I’m confused. I tried reverting to Aspose.PDF 25.4.0

No difference

Because it seemed to be related to images I tried reverting Aspose.Imaging to 25.4.0

No difference

Brought all nuget packages up to date again. Aspose.PDF 25.5.0 and Aspose.Imaging 25.5.0

Then (since this code is executed only when there is exactly 1 image on the page)

Using oFS As New IO.FileStream(path:=sPageImage, mode:=IO.FileMode.Create)
  oPage.Resources.Images.Remove(oPage.Resources.Images.Item(1))
  oPage.Resources.Images.Add(oFS)
  oFS.Close()
End Using

Problem goes away

Still would appreciate it if this could be investigated

@rozeboosje

We will surely investigate the issue. Can you please share sample PDF document and some more steps to replicate the issue in our environment so that we can test and address it accordingly?

Hello @asad.ali

That is the most peculiar thing about this issue.

There was no .PDF document.

We wrote a large chunk of code - years ago at this stage - that converts various file types to PDF for “previewing” purposes. The details are not important.

The astonishing bit of this problem is that that snippet of code does not appear to be triggered at all. It was in a branch of an IF statement that I found, after some investigation, to no longer be executed under any circumstances.

While debugging, as I am stepping through the code in Visual Studio, the error is raised as soon as the code hits the procedure that contains this statement, even though it never actually reaches that statement.

It’s baffling!

I’m going to try and reduce the procedure to its bare essentials to see whether I can trigger the issue that way

Got it. It has nothing to do with Aspose.PDF

We use a lot of Aspose components in our software

The problem starts happening once we add the Aspose.OCR nuget package to the Solution

The problem is resolved when I change:

oPage.Resources.Images.Item(1).Save(stream:=oFS,
                                        format:=Drawing.Imaging.ImageFormat.Jpeg)

To

oPage.Resources.Images.Item(1).Save(stream:=oFS,
                                        format:=Aspose.Pdf.Drawing.ImageFormat.Jpeg)

Adding Aspose.OCR seems to cause a problem with “Drawing.Imaging” which is resolved once I explicitly type the format parameter to make sure it uses Aspose.Pdf.Drawing.ImageFormat

Hm. Still confused

The problem “goes away” when I make this change in a very small “test solution” when it resolves ths .Save statement to

    Sub Aspose.Pdf.XImage.Save(stream As IO.Stream, format As Aspose.Pdf.Drawing.ImageFormat)

In our actual main Solution, a solution with almost 90 projects in it, when I hover the mouse over the .Save statement it gives me

    Sub Aspose.Pdf.XImage.Save(stream As IO.Stream, format As Drawing.Imaging.ImageFormat)

Where I am guessing that the latter is short for System.Drawing.Imaging.ImageFormat

Ahhhhhh!!!

It seemed perfectly fine until I right-clicked on the project’s References and I c hose “Migrate packages.config to PackageReference”

At that point it all went wrong

WpfApp5.zip (11.8 KB)

@rozeboosje

We opened the application in Visual Studio but it is not even loading the packages correctly. It is giving error. Can you please share some screenshots of the errors that you are facing in your system while working with it in both cases?

Hello @asad.ali

Here are the steps I followed to create the project.

  1. Create a new Visual Basic project for WPF, targeting .NET Framework 4.8
    Image1.jpg (12.3 KB)

  2. Target .NET Framework 4.8
    Image2.jpg (25.9 KB)

  3. Add the Aspose.PDF nuget package
    Image4.jpg (60.3 KB)

  4. Please note that this will install a large amount of additional packages
    Image5.jpg (48.0 KB)

  5. After the install there are warnings for deprecated packages and a total of 21 packages with updates. Apply all these updates
    Image6.jpg (26.1 KB)
    Image7.jpg (48.0 KB)
    Image8.jpg (95.8 KB)
    … also note that you will have to repeat this as after the updates there are further packages that need updating
    Image9.jpg (36.7 KB)

  6. Migrate the nuget packages to package references
    Image10.jpg (32.1 KB)

  7. Note that this is done without any problems
    Image11.jpg (8.6 KB)

  8. Add the code I sent you before to any part of the Source Code. Application Startup is as good a place as any. Leave the first statement uncommented and note how it won’t accept it now:
    Image12.jpg (145.3 KB)

  9. Now add the Aspose.OCR package
    Image13.jpg (6.6 KB)

  10. This installs two additional packages for Microsoft.ML.Onnx
    Image14.jpg (12.6 KB)

  11. There are updates for these packages. Apply them
    Image15.jpg (15.5 KB)

  12. In the source code, comment out the first statement, i.e. the one it won’t accept in the IDE, and uncomment the second one. It will accept the second statement in the Editor, but then hit the green “play” button to run the code, and this happens:
    Image16.jpg (119.8 KB)

Please note

  • This happens even if you add a breakpoint to the first statement in the code block shown in image12
  • This happens even if you don’t update the nuget packages for Microsoft.ML.Onnx, i.e. revert back to the transitive packages for version 1.20 of these
  • The problem goes away when you uninstall the nuget package for Aspose.OCR

@rozeboosje

The issue seems like related to Aspose.OCR due to some its dependencies. Nevertheless, we will surely investigate it. Can you please confirm a last thing? Have you tried using 4.8.1 framework? Did the APIs show same behavior with 4.8.1 version of the API?

Hello @asad.ali

I found the following when following the same steps as before but with a Project targeting .NET Framework 4.8.1

Firstly, adding the nuget package for Aspose.PDF is less painful. It didn’t seem to need any other packages.

When I added Aspose.OCR it did ask to add additional packages for Micrsosoft.ML.Onnx, System.Memory, System.Text.Encoding.CodePages, System.Buffers, System.Numerics.Vectors and System.Runtime.CompilerServices.Unsafe.

When I added those, and after ugrading them and migrating the nuget packages to Package References it complained that it needed an additional reference to System.Drawing. I added that directly from Visual Studio. No corresponding package was available through nuget.

After that the behaviour was exactly the same as with .NET Framework 4.8 - The IDE will not accept the first statement, and while the second statement does not present an error and it builds the application without errors, when it’s run it throws the same error "Method not found: 'Void Aspose.Pdf.XImage.save…

@rozeboosje

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): OCRNET-1039

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.

1 Like