Structured Document Tags disappearing

I am writing a function which inserts rich context controls into an existing document.


The code essentially creates a run of text, creates an SDT, inserts the run into the SDT, then inserts the SDT into the document near a bookmark. When I go through the debugger the code executes without exception, however on my first run-through the SDT is always removed. The text that was inserted only in the SDT (it never existed in the doc, it was created and inserted directly into the SDT) is still present, but the SDT itself is gone. This makes me think that the SDT existed at one point, but was eventually removed. On subsequent runs this executes as expected where the SDT exists with the text inside.

My first thought was that the text was being coerced out of OOXML format (maybe HTML?) and then back to OOXML and something about his process removes the SDT, but I have not found anywhere in our codebase that would do that.

Has anyone experienced similar issues or have suggestions on where to look?
Hi there,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we'll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click 'Reply' button that will bring you to the 'reply page' and there at the bottom you can include any attachments with that post by clicking the 'Add/Update' button.