NullReferenceException occurs when copy page in C#

Hi,
I got System.NullReferenceException:“Object reference not set to an instance of an object.” when I try to copy page to new file.

Tested OSs were Win7 and Win10
.NET target platform is .net 6.0
Using SDK: Aspose.PDF for .Net 24.3

Test code

void testCopy(string filename)
{
    // Open first document
    Document pdfDocument1 = new Document(filename);
    // Create second document
    Document pdfDocument2 = new Document();

    for (int i = 1; i < pdfDocument1.Pages.Count; i++)
    {
        pdfDocument2.Pages.Clear();
        pdfDocument2.FreeMemory();
        pdfDocument2.Pages.Add(pdfDocument1.Pages[i]);
        pdfDocument2.Save(filename+i+".copy.pdf");
    }

}

Exception detail

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Aspose.PDF
  StackTrace:
   在 Aspose.Pdf.Forms.Field.#=zLkx3WGfdEaM6DjrgCw==()
   在 Aspose.Pdf.Forms.Form.AddFieldAppearance(Field field, Int32 pageNumber, Rectangle rect)
   在 Aspose.Pdf.PageCollection.#=zzTp2$gJ5YI8t(Page #=z5pkMFAk=)
   在 Aspose.Pdf.PageCollection.#=zEtWNLco=(#=zzLq4EBXXnJzaMujtRdvyNPLXY5fDo4RP4Q== #=z66xC9rA=, Int32 #=zSqrENbM=, Page #=zUPvZvJM=)
   在 Aspose.Pdf.PageCollection.Add(Page entity)
   在 Program.<<Main>$>g__testCopy|0_6(String filename) 在 C:\.NET\ConsoleApp1\ConsoleApp1\Program.cs 中: 第 114 行
   在 Program.<Main>$(String[] args) 在 C:\.NET\ConsoleApp1\ConsoleApp1\Program.cs 中: 第 122 行

Using file
交易公告.7z (155.9 KB)

@kngstr

You are saying that you are trying to convert the document into image. However, you shared different code snippet. Can you please share the correct code that you are using to convert PDF into image?

@asad.ali

Sorry. It should be copy page to new file.
Test code is right.

@kngstr

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-57076

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.