TOC in document prevents replacements with Range.Replace below the TOC if IgnoreFields = True

This occurs only with some TOCs in some documents, not with others, I’m not sure why.

Here is the input file and the expected result.
input.docx (84.1 KB)
expected.docx (84.3 KB)

Try running the following on the document:

document.Range.Replace("Redacted", "Deleted");

Observe that every instance of “Redacted” has been replaced by “Deleted” as expected.

Now try:

document.Range.Replace("Redacted", "Deleted", new FindReplaceOptions { IgnoreFields = true });

Observer that only the first two instances of “Redacted”, above the TOC, have been replaced. The rest remain unchanged. This is the bug.

This has happened across multiple different documents from various sources, but it doesn’t happen in all documents containing TOCs. Take the Input document, open in Word, and from the References tab, remove the TOC and then add a new one by selecting “Automatic Table 1” from the Table of Contents button. Save the doc, and try to run the replace operation on it with IgnoreFields = true, and this time it will work as expected.

I’m not sure what’s going on, but it seems like something is causing all of the text below the TOC to be ignored, as if all of it was inside a field…

@ssmolkin1

We have tested the scenario and managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-22955. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

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