Getting StackOverflowException exception on docx merging

I’m trying to merge the following document with the other document, but during file load (var srcDoc = new Document(Files[i])) it throws the exception (Exception of type ‘System.StackOverflowException’ was thrown.).
I’m using the Aspose.words 24.9.0 version but also tried with latest 25.5.0 nuget, still getting same issue.
Can you guide me how to merge this with other without getting exception?
1.docx (705.9 KB)

Keep in mind same code is working fine with other document even with larger size.

@Ahsen

It seems that you are encountering a StackOverflowException when trying to merge a document with itself using Aspose.Words. This type of exception typically occurs due to excessive recursion or an infinite loop in the code.

To resolve this issue, you can try the following approaches:

  1. Use a Different Destination Document: Instead of merging the document with itself, create a new destination document. This can help avoid potential issues related to the document structure or references.

    Here’s a sample code snippet to illustrate this:

    Document srcDoc = new Document("path/to/your/document.docx");
    Document dstDoc = new Document(); // Create a new document
    
    // Append the source document to the new destination document
    dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
    
    // Save the new document
    dstDoc.Save("path/to/your/merged_document.docx");
    
  2. Check for Recursive References: Ensure that there are no recursive references within the document itself, such as bookmarks or hyperlinks that point back to the document.

  3. Update Aspose.Words: Although you mentioned trying the latest version, ensure that you are using the most recent stable release of Aspose.Words, as updates often include bug fixes and performance improvements.

  4. Simplify the Document: If possible, try simplifying the document by removing complex elements (like nested tables or large images) to see if that resolves the issue.

If these suggestions do not resolve the problem, consider sharing a minimal reproducible example or the specific structure of the document that is causing the issue. This can help in diagnosing the problem more effectively.

For more detailed guidance on merging documents, you can refer to the official documentation on joining Word documents together, which provides insights into using the AppendDocument method effectively [1].

Sources:
[1]: Joining Word Documents Together|Aspose.Words for .NET

@Ahsen
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): WORDSNET-28223

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.