A family of Microsoft word processing software products for creating web, email, and print documents.
Hi, ApsSanj
The common clue is that the exception appears around a programmatic save, but I would not conclude from the logs alone that DocumentOpen fired a second time. DocumentOpen runs when a document opens; Word also has a separate DocumentBeforeSave event that runs before an open document is saved. A call made from a save-related handler, or another callback in your add-in, could account for the later UpdateTagsIfBroken() log entry. That is something to verify, not yet a confirmed diagnosis.
Here are some suggestions you can try:
Capture the path before saving in the copy routine. Read this.wordDocument.FullName before this.wordDocument.Save(), rather than making the next line depend on the same document reference still being usable. If Save() throws, or a subsequent access to the document fails, stop that operation instead of continuing with the cached object. A cached path can help you identify the document, but it does not make an invalid document reference valid again.
Trace every route into UpdateTagsIfBroken(), not just DocumentOpen. In particular, check your save-related handlers and any callbacks they invoke. Log entry and exit for Application_DocumentOpen, UpdateTagsIfBroken(), and each programmatic Save(), along with a per-operation ID and the document path captured before saving. That should tell you whether this is a second open event, a nested call during the first one, or a separate call after it. Word’s documented save event makes that distinction worth checking.
Guard the save inside Application_DocumentOpen. If your own save-related code can call back into document-processing code, use a per-document “save in progress” guard so it does not process that same document again while your doc.Save() is running. Clear the guard in a finally block. I would avoid a single application-wide flag unless you intend it to suppress processing for every open document.
Test the file location separately from the code path. On an affected machine, try the same document and add-in workflow from a non-synced local folder, then from the OneDrive-synced folder. Keep the Word build the same for that comparison. OneDrive-synced Office files have their own collaboration integration, but the location alone does not establish that synchronization caused this exception, and turning AutoSave off does not settle the question.
Reacquiring the document may be reasonable after you confirm that the original reference is no longer usable and identify the correct document. I would not make reacquisition by name the primary fix yet, especially with multiple documents open. First determine which call runs after the save and whether it is using a reference retained from an earlier step. I also would not label this a Word 2607 regression without a comparison against another build using the same file and workflow.