Bug Word 2013: COM exception comparing documents

I’m breaking the rhythm of the series on Web Add-ins to report a bug that was discovered by a developer in the VSTO forum, this week.

This is occurring in a scenario where a called procedure returns a Word.Document object to a calling procedure, then is called again. On the second call, the Word.Document object (being re-used in the called procedure) is causing the exception. The code works if the Document object is closed (thus fully releasing the COM object from memory) or if each call starts a new instance of the Word.Application. But neither of these approaches was acceptable.

The developer finally ended up contacting Microsoft and they discovered that the fault lies with setting the Visibility parameter in Documents.Open to False. Changing the Visibility to True resolves the issue. Also, opening a new (empty) document before calling the procedure allows the code to run without issue.

Leave a Reply