Content.Replace(string, string) not working consistently

We are using the document.Content.Replace(string,string) method to replace token values in our document.

In our document we have plain-text tokens which we look for in code and swap out for values:

Examples

<DATA_PROCESSING_PERSONALDATA>
and
<DATA_PROCESSING_SPECIALCATEGORIES>

However we are finding that the behavior is inconsistent.
Sometimes it works … sometimes it doesn’t.

I have an example screenshot below where we have the same word document with the exact same code and same tokens. Running the code twice you can clearly see two of the tokens have NOT been replaced.

Are there any known issues with this method?

Is there some kind of async problem we should be aware of?

Hi Martin,

Without reproducing your issue I cannot say for sure, can you please send us your Word document and specify what plain-text token you cannot replace in it?

I guess this specific plain-text token may not be inside the document’s body. Instead, maybe Microsoft Word is automatically adding it when opening the file. For example, it could be a content control with XML binding that is automatically updated when open. You can verify this by resaving the document with Microsoft Word and then trying to replace the token with GemBox.Document.

Anyway, please send us a small Visual Studio project that reproduces your issue so that we can investigate it. You can send it to us via email or support ticket, see the Contact page.

Regards,
Mario

Hello Mario

This is just some text typed into the document.
We aren’t using any kind of content controls or binding.

The screenshot shows the two examples where this text is used.
In the image on the left the text <DATA_PROCESSING_PERSONALDATA> was not replaced.
In the image on the right the text <DATA_PROCESSING_SPECIALCATEGORIES> was not replaced.

Given that both text values have been correctly swapped out at runtime (just intermittently) it can’t be a problem with how they appear in the document.

Hi Martin,

I was unable to reproduce this problem.
Please create a small Visual Studio project that reproduces your issue so that we can investigate it.

Regards,
Mario