NullReferenceException when CopyLogicalStructure = true (Aspose.PDF 25.9.0)

Title:
NullReferenceException: Aspose.PDF PdfFileEditor.Concatenate() fails when CopyLogicalStructure = true

Product Version:
Aspose.PDF for .NET 25.9.0

Environment:

  • .NET 8.0
  • Running in Azure Function

Issue Description

We are encountering a System.NullReferenceException when concatenating multiple PDF files using PdfFileEditor with CopyLogicalStructure = true.

The error occurs only for some PDFs — typically those that do not contain a structure tree / tagging information. When CopyLogicalStructure = false, the merge succeeds.

This appears to be a regression or unhandled case in Aspose.PDF 25.9.0 regarding logical structure copying.


Code Sample (minimal reproducible)

var editor = new PdfFileEditor();
editor.CopyOutlines = false;
editor.CopyLogicalStructure = true;
editor.CorruptedFileAction = PdfFileEditor.ConcatenateCorruptedFileAction.StopWithError;

string output = "output.pdf";
string[] files = pdfFilesToConcatenateList.ToArray();

editor.Concatenate(files, output);

Exception Details

System.NullReferenceException: Object reference not set to an instance of an object.
Source: Aspose.PDF

at #=zpGIgK4ZLFojnQzGTXnZ2Kvp7$I3jqrAkMucm5n1RtZMB.#=zin7vvabuvT71Bf3K3g==(Page)
at #=zrwedPKSosqSNHMtMQQJJEThmNlwPXTy6M70SiiA=.#=znpCSrJAMYad0(Document, Int32, Document)
at Aspose.Pdf.Facades.PdfFileEditor.#=zyp_$SVg=(Document, Document, ...)
at Aspose.Pdf.Facades.PdfFileEditor.Concatenate(String[] inputFiles, String outputFile)

The stack trace clearly indicates the failure occurs inside the Aspose internal method that processes page structure elements (MCIDs, StructTreeRoot, etc.).


Analysis

Based on our tests:

  • The issue reproduces only when at least one input PDF lacks logical structure (i.e., untagged or partially tagged PDF).
  • This may be a regression in 25.x or an unhandled null condition in structure-copying code.

We require CopyLogicalStructure = true for WCAG/PDF/UA workflows, but the current behavior makes merging unreliable.


Request

  1. Please confirm whether this is a known issue or regression.
  2. Provide a fix or patch to prevent the NullReferenceException.
  • Expected behavior: Aspose should skip missing structure nodes instead of throwing.
  1. Provide a recommended approach for handling mixed PDFs (tagged + untagged) with logical structure copying enabled.

@abdulkadirsabirbohari

Summary
A System.NullReferenceException is thrown from PdfFileEditor.Concatenate() when CopyLogicalStructure is set to true. The crash occurs only with source PDFs that do not contain a tagging (logical‑structure) tree. Setting CopyLogicalStructure to false allows the merge to complete.

Why it happens
During concatenation the logical‑structure copy routine expects each input document to have a non‑null structure‑tree object. When an input PDF lacks this object (i.e., it is un‑tagged), the routine attempts to dereference it, resulting in the null‑reference exception. This behaviour is observed in the 25.x version you are using.

What to do next

  1. Check for a newer library build – If a newer Aspose.PDF for .NET release is available, update and verify whether the issue persists. Many regressions are addressed in subsequent patches.
  2. Collect diagnostic information – Enable Aspose internal logging to capture detailed traces that can be shared with Aspose support:
Aspose.Pdf.Logging.Logger.SetLogLevel(Aspose.Pdf.Logging.LogLevel.Debug);
Aspose.Pdf.Logging.Logger.SetLogFile("AsposePdf.log");

Attach the generated log file to your support request.
3. Prepare a minimal reproducible sample – Create a small set of PDFs that includes at least one tagged and one un‑tagged file. Note the exact Aspose.PDF version and the .NET runtime you are using.
4. Open a support ticket – Provide the following to Aspose support:

  • Description of the problem and the stack trace.
  • The minimal reproducible sample PDFs (if possible).
  • The log file from step 2.
  • The version of Aspose.PDF for .NET you are using.
    Request confirmation whether this is a known regression and ask for a fix or an official workaround.
  1. Temporary workaround – If you must continue processing while awaiting a fix, consider merging the PDFs with CopyLogicalStructure = false and, if required, apply tagging to the resulting document in a separate step using the Document API. This approach avoids the null‑reference path but may require additional post‑processing to meet WCAG/PDF‑UA requirements.

Until an official fix is released, the safest path is to avoid enabling CopyLogicalStructure for PDFs that may be un‑tagged and to work with Aspose support using the information above.

Note: The suggestions above are based on the observed behaviour and standard troubleshooting practices; they do not constitute a confirmed fix.

:warning: I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.