Error with UpdateFields

Hello,

When I try to use “UpdateFields” on some document I’ve got this error “Arithmetic operation resulted in an overflow.”. If I open the document, modify it and save and try again, it works.

Aspose.Words.NET 25.10.0

In the attachment the code and the document I’ve used for the test.
element.zip (6.4 MB)

Thank you, best regards.

@ISIWARE

The error “Arithmetic operation resulted in an overflow” when using UpdateFields in Aspose.Words can occur due to various reasons, such as issues with the document’s content or structure. Since modifying and saving the document manually resolves the issue, it suggests that there might be some internal state or field that needs refreshing.

Here are a few steps you can take to troubleshoot and potentially resolve the issue:

  1. Ensure Document Integrity: Before calling UpdateFields, check if the document is corrupted or has any unusual content. You can try opening and saving the document programmatically to refresh its state.

  2. Use Document.Save Method: If you haven’t already, try saving the document after loading it and before calling UpdateFields. This can help reset any internal states.

    Document doc = new Document("path/to/your/document.docx");
    doc.Save("path/to/your/temp_document.docx"); // Save to a temporary file
    doc.UpdateFields(); // Now update fields
    
  3. Check for Complex Fields: If your document contains complex fields (like nested fields or fields with calculations), try simplifying them or breaking them down to see if that resolves the overflow issue.

  4. Update to Latest Version: Ensure you are using the latest version of Aspose.Words, as updates often include bug fixes and improvements.

If the problem persists, consider sharing the document with Aspose support for further analysis, as they can provide more specific insights based on the document’s content.

If you have any further questions or need additional assistance, feel free to ask!

@ISIWARE Unfortunately, I cannot reproduce the problem on my side. Also, As I can see in your code example the license is set for Aspose.Slides, but not for Aspose.Words. Could you please check?
If possible, could you please create a simple console application, that throws an exception on your side?