none
Runtime Callable Wrapper Issue with Word Add-In RRS feed

  • Question

  • I have developed a VSTO add-in that exports a large amount data from Word to Excel.  Every thing works fine with a short Word document.  However, when the document gets too large, I get this error message from Visual Studio:

    Transition into COM context 0xb7f81f0 for this RuntimeCallableWrapper failed with the following error: System call failed. (Exception from HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED)).

    Visual Studio gives me this advice: To avoid this problem, please ensure that all COM contexts/apartments/threads stay alive and are available for context transition, until the application is completely done with the RuntimeCallableWrappers that represents COM components that live inside them.

    Can anyone offer a suggestion on how to accomplish this or point me in the right direction?  I have objects for the Word application and document as well as for the Excel application, workbook, and worksheet.  I'm guessing garbage collection is collecting something before it should.

    Thanks for your help.



    • Edited by MattP34 Friday, June 9, 2017 2:47 PM
    Wednesday, June 7, 2017 7:53 PM

Answers

  • I found a solution for this here: https://stackoverflow.com/questions/22606666/disconectedcontext-was-detected.

    I just had to add this line:

    System.Windows.Forms.Application.DoEvents()
    According to the post at the link above, this prevents one application from blocking others.  In my case, I have Word and Excel open.  I added the line of code above to the For Loop that iterates through the rows in the Excel workbook.


    • Marked as answer by MattP34 Wednesday, June 7, 2017 8:26 PM
    • Edited by MattP34 Wednesday, June 7, 2017 8:27 PM
    Wednesday, June 7, 2017 8:26 PM