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?