Random to throw NullReferenceException when save PDF to Docx

Description

Aspose.PDF random to throw NullReferenceException when save some PDF to Docx via Parallel.

Environment

  • Windows 10 .NET 4.7
  • Aspose.PDF for .NET 22.12

Code

    Parallel.For(1, 6, (i) =>
    {
        var doc = new Aspose.Pdf.Document(@"C:\Users\XCL\Desktop\test\source" + i + ".pdf");
        doc.Save(@"C:\Users\XCL\Desktop\test\target" + i + ".docx", Aspose.Pdf.SaveFormat.DocX);
    });

Note

We need to run code above more times ( I ran it 15 times) and we will see the exception:
image.png (186.7 KB)

Test Files

test.zip (277.9 KB)

@xucongli1989

We have logged this problem in our issue tracking system as PDFNET-53361. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier (filed as PDFNET-53361) have been fixed in this update.

I’m having the same issue in Aspose PDF .NET 23.10 when I want to save the document to a Stream.

@cerbone

Can you please share your sample source document with us so that we can test the scenario in our environment and address it accordingly.

Hi Asad,

Env used: Docker Image with .NET Core 6.0 and Windows 11 IIS with .NET Core 6.0
I create the PDF by code, you can reproduce the problem with the code below:

       byte[]? docByte = null;
       var x = new Aspose.Pdf.Document();
       using (var memorystream = new MemoryStream())
       {
           x.Save(memorystream, Aspose.Pdf.SaveFormat.DocX);
           memorystream.Seek(0, SeekOrigin.Begin);
           docByte = memorystream.ToArray();
       }

       return docByte;

@cerbone

Instead of Aspose.PDF for .NET, we request you please use Aspose.Pdf.Drawing and if issue still persists, kindly share the docker file for our reference so that we can investigate with the same configuration and address the issue accordingly.

The issue seems to appear also when running unde windows and macOS. It is not limited to docker image.

P.S. I got the same error when I install Aspose.PDF.Drawing.

P.S2: when save format is Saveformat.PDF it works, but I need to save it as DocX.

@cerbone

While testing the scenario using 23.10 version of the API in our environment, we noticed different exception that displayed the meaningful error description:
image.png (3.9 KB)

After adding the page in the document, the code was executed just fine.

byte[]? docByte = null;
var x = new Aspose.Pdf.Document();
x.Pages.Add();
using (var memorystream = new MemoryStream())
{
    x.Save(memorystream, Aspose.Pdf.SaveFormat.DocX);
    memorystream.Seek(0, SeekOrigin.Begin);
    docByte = memorystream.ToArray();
}