Asked by:

Question

I my document-level customization I'm experiencing the following behavior:

When opening a document, immediately entering footnotes and clicking between a <note> start and end tag I get this error:

System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component. at Microsoft.Office.Interop.Word.XMLNode.get_BaseName() at ...

But if I wait a few seconds before clicking between the start and end tags it all works fine. I see the same if I set a break point where the error occurs. When quickly placing the mouse over the node.BaseName I see an exception but if I wait a few seconds and exit and reenter the mouse the exception is replaced with the correct node name...

I guess it's probably hard to reproduce without our entire codebase... but what happens is this (bear in mind that our editor is based on Word 2003 and is displaying the XML structure (the pink xml tags) of the document in the document window):

Open an existing document with foot or end notes As soon as the document is open we click a button that performs the following:

Then if the cursor is placed in some text between a <Note> and a </Note> tag in the notes window (displayed below the document) we get the aforementioned error. But only if the operations is performed fairly "snappy". If we wait a couple of seconds before clicking the notes window everything works just fine...

That particular bug had to do with XML tags in the header/footer area of the document. It was also very much reproducible.

It's not at all clear where in the document the XML tag is that's giving you a problem. As best I can tell, the tag is actually in a Footnote area? So I don't think it's the same bug.

It's quite likely Word is still doing some internal processing when you can already click on the document, since your problem only shows up in the first second or two after opening. You might try building a "DoEvents" kind of loop in at the end of ThisDocument_Startup and see if that makes any difference. Or start a Timer there, then check it in a WindowSelectionChange event, loop if it's too soon - see if these things can help close the "window of opportunity".Cindy Meister, VSTO/Word MVP

Yes you are correct in assuming that the problematic xml tag is in the Footnote area.

Am I correct in understanding that you want me to create some sort of "Do While events are being fired" loop at the end of ThisDocument_Startup? And only end ThisDocument_Startup when all events have completed?