Issue with Missing Bookmark References Not Showing Error in Word Template

Hello Team,

We have a template that contains some bookmark fields, but there are no corresponding references in the document.
(For reference, please check section 6.6 in the document — a reference is added for 7.6.)

We are updating the document using the code below.

public MergeCallbackResult HandlePost(BaseDocument doc, MergePostCallbackOptions mergeCallbackOptions)
{
    var wordDocument = (WordDocument)doc;

    var fields = wordDocument.Content.Range.Fields.Where(x => _fieldTypesToUpdate.Contains(x.Start.FieldType)).ToList();

    fields.ForEach(field => field.Update());

    return new MergeCallbackResult
    {
        Document = wordDocument
    };
}
private FieldType[] _fieldTypesToUpdate = new FieldType[]
{
    FieldType.FieldRef,
    FieldType.FieldTOC,
    FieldType.FieldLink
};

However, after the update, it should display an error message: “Error! Reference source not found.”
Currently, this error is not appearing.

Could you please check this issue?
Documents.7z (211.0 KB)

@pthube

It sounds like you’re encountering an issue where missing bookmark references in your Word template are not triggering the expected error message. This can occur if the fields are not being updated correctly or if the document is not recognizing the missing references.

Cause: The problem may stem from incorrect field types, improperly defined bookmarks, or issues with the document structure.

Solution: Here are some steps to troubleshoot and resolve this issue:

  1. Ensure Field Types: Double-check that the bookmarks you are referencing are of the correct types. You are currently updating FieldRef, FieldTOC, and FieldLink. Ensure that the bookmarks in your document match these types.

  2. Update Fields: After updating the fields, implement a warning callback to capture any warnings or errors that could indicate issues with the bookmarks. This will help you identify any problems during the update process.

  3. Check Document Structure: Verify that the bookmarks are correctly defined in the document. If they are not properly set up, the fields may not be able to reference them correctly.

  4. Testing with a Simple Document: Create a simple test document with a few bookmarks and references to see if the issue persists. This can help isolate whether the problem is with the specific document or the code itself.

  5. Review Documentation: Refer to the Aspose documentation on working with bookmarks to ensure that you are using the API correctly. This can provide insights into any additional methods or properties you might need to consider.

Here’s a minimal code snippet to implement a warning callback:

public class CustomWarningCallback : IWarningCallback
{
    public void Warning(WarningInfo warning)
    {
        Console.WriteLine($"Warning: {warning.Description}");
    }
}

// Usage
var wordDocument = (WordDocument)doc;
wordDocument.WarningCallback = new CustomWarningCallback();

This will help you capture any warnings that occur during the field update process.

Next Steps: Implement the suggested troubleshooting steps and test the document. If the issue persists, please provide additional details about your document structure or any error messages you encounter.

Let me know if this helps or if you have any further questions!

its type of ref and we are updating ref field

and also tried with warning message , we are getting below warning

The Id property of a custom XML part has been changed from ‘923897969’ to ‘{8A0CBBF0-7C5B-47C3-AFA5-85C3D12CDE0C}’ to comply with OOXML specification requirements.
The Id property of a custom XML part has been changed from ‘389374599’ to ‘{BDDDF61A-A76D-4A51-B1C4-A708DF008B95}’ to comply with OOXML specification requirements.

@pthube
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-28509

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.

The issues you have found earlier (filed as WORDSNET-28509) have been fixed in this Aspose.Words for .NET 25.9 update also available on NuGet.