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.
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'm wondering if I'm hitting the bug mentioned here:
Based on your information above, actually I cannot ensure this is bug mentioned in the above link. Would you please tell me the steps reproducing this scenario and office version?
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Thanks for your answer.
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:
CommandBarControl cbarCtrl = _document.Application.CommandBars.FindControl(MsoControlType.msoControlButton, 764, null, null);
if (cbarCtrl != null) cbarCtrl.Execute();
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?