Error HRESULT E_FAIL has been returned from a call to a COM component.


  • And back to the error with no meanings:


    I’ve created a document, published it on an IIS, and opened it from the IIS, resolved the security problems, and now facing this error message:


    Error HRESULT E_FAIL has been returned from a call to a COM component.


    ************** Exception Text **************

    System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.

       at Microsoft.Office.Core.CommandBarControls.Add(Object Type, Object Id, Object Parameter, Object Before, Object Temporary)

       at CreditCommentsDoc.ThisDocument.ThisDocument_Startup(Object sender, EventArgs e)

       at Microsoft.Office.Tools.Word.Document.OnStartup()

       at CreditCommentsDoc.ThisDocument.FinishInitialization()

       at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecutePhase(String methodName)

       at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecuteCustomization(IHostServiceProvider serviceProvider)



    When the document runs from my machine, it runs just fine


    According to the error message, there was a problem, adding a button to the toolbar, and that’s it, figure it out, you are on your own.


    Thank you for the meaningful errors MS, if one day I am writing an application that will be used by Microsoft; I will defiantly make sure I’ll remember that :-)


    Ok, I am not that bad :-)

    Thursday, March 02, 2006 9:49 PM


All replies

  • I'm not sure quite what you're doing here as I don't have the code you are executing but it seems like you are trying to add a button to the CommandBarControls collection.

    If you are doing this from inside a VSTO customization which runs when the document is opened from within IIS then there are any number of reasons this might fail.

    VSTO was not designed with this scenario in mind. The core server scenario uses the ServerDocument object to open Word and Excel documents _without_ starting the application and allows the developer to manipulate cached data:

    If you could explain further what you're trying to achieve I may be able to suggest a way to do it.



    Monday, March 06, 2006 11:49 PM
  • I stopped the modifications over the code, I will try to go to the project later, but here is the idea.


    In the server side, I am using the server document to manipulate the document, and after the modifications, this document must go to the client, and the client opens it.


    For the client, it is a document coming from IIS, the only difference, this document has a DLL file attached to it.


    All what this DLL does, is adding a new button next to the save button, and this button will save the data back to a web service.


    So there are 2 projects, one on the server behind IIS, and one that will execute on the client in Word.


    The only problem here is the client code cannot modify the Microsoft Word toolbar once the document is opened from IIS using a web browser.


    This code can modify the toolbar when the document runs from the local machine.


    The solution that I am building is no different from an InfoPath / SharePoint solution, but since the previous 2 are extremely limited and cannot work with large documents (in size), and large amount of documents, we are going to build a solution with Word and ASPX.


    Although Word is very powerful when handling large documents, it seems Word has lots of limitations in other areas.


    Anyway, thank you for the help, and I hope MS has more descriptive errors in the future, a bit more in the description = lots of saved time to the developer.

    Tuesday, March 07, 2006 2:09 PM
  • I had the same exact problem. What I did was to create another VSTO project that adds the command button to ther bar, and I save the change in the document. Once that's done, I use that Word document on my other project. This way, you have the button in the bar as though it was done on design time. It's a workaround, I know, but it accomplishes the goal.
    Wednesday, March 08, 2006 6:32 PM
  • Any official response from MSFT? I too am working through this, and if solved will be of tremendous benefit!



    Sunday, June 11, 2006 6:16 PM
  • I stopped  trying actually to run a word document from IIS directly, the VSTO object module is over secured, to a level that makes it useless, and Microsoft Word is not designed to work from IIS.

    I found a workaround with click once deployment (to produce reports).

    1- Create a Windows application.

    2- Reference the Word 11 or Word 12  .net libraries.

    3- Use  the libraries to show Word and hide your Windows form.

    4- Use the click once deployment to publish everything to the IIS and run it from there.

    This way you will bypass all the restrictions (the .net security) and all related errors.


    Another thing, I am not using Word instead InfoPath, both are too slow, I am using a windows form instead, with the regular controls, and Microsoft Word inside the form (using the Windows API) for the rich text.


    At this stage, Microsoft Word is wonderful for reporting,  but premature for data entry,  there are still tons of things missing.

    Excel on the other hand is much advanced, but both need a bit more work from MS.

    Sunday, June 11, 2006 7:34 PM
  • I appreciate your help very much! Advice from the trenches is most beneficial!

    Now question time. In my situation, I have a web-based app that users will need to use to have the system populate documents with context-sensitive data (based on a context-sensitive template), then bring them up for possible editing, then printing. This saves a record of the document, and then at any time, the user can click a link in the app to bring that document up again. (for possible editing or printing) If I can't use IIS as the container for this document, I was considering causing the linked document to come up in word instead. But, I agree that I will have much more control of a windows application (using windows forms). Do you know of a way that I can, in a web page, cause the execution of a windows executable that is installed on a users machine?



    Monday, June 12, 2006 11:32 AM
  • When you say "opened from IIS using a web browser" do you mean that you're trying to run the Word document embedded in IE after it downloads?

    I agree the error in this case is not descriptive or helpful. It would seem like this is a known issue in the IE case and there's already a bug on it:

    As for the general comment about launching Word from within IIS this is not a supported scenario as it severely impacts application scalability.



    Monday, June 12, 2006 3:33 PM
  • Well, IE was bringing up the linked document within the container of IE. But I modified the file type settings to force IE to spawn a word instance.

    And the application I was mentioning to open from IE is a custom windows form app that I created (as applicble to the post before mine.)

    Monday, June 12, 2006 5:19 PM
  • All:

    Check this out. I'm trying to get this sample to work, but it looks promising!


    Tuesday, June 13, 2006 5:23 PM
  • To Run Windows Applications from the web, you need the click once deployment, more information at:

    Monday, June 19, 2006 11:14 AM
  • I was getting the same error from VS 2005 Pro while trying to save a *.aspx page. I'd been testing on LOCALHOST but was not running the page at the time. I closed all my IE windows and it cleared up the issue. Not sure if IE and VS were somehow colliding. Hope this helps others who run into this issue.
    Friday, December 01, 2006 2:53 PM
  • I am getting this error on Windows Server 2003 R2 when trying to run the DFSR diagnostic report wizard.  It worked fine a week ago...

    I know nothing about COM or programming.  Could someone please help?

    Monday, December 11, 2006 12:53 PM
  • for general questions concerning interoperability with COM, ask in the dotnet.interop.framework newsgroup

    Monday, December 11, 2006 2:20 PM
  •  tcp179 wrote:

    I am getting this error on Windows Server 2003 R2 when trying to run the DFSR diagnostic report wizard.  It worked fine a week ago...

    I know nothing about COM or programming.  Could someone please help?

    Me too; i just googled the phrase after the DFSR diagnostic report thing started doing this a week or two back.

    Feel free to email me at andyfearlessAT(NOSPAM) and if either of us find a fix we'll notify the other

    i installed the latest hotfixes (including IE7) on the servers in the last two weeks - maybe its that? Do you have IE7 installed on the servers in question?




    sodding MS; whose daft idea was it to make IE7 a CRITICAL update?

    Tuesday, December 12, 2006 10:40 AM
  • i don't believe it.



    "You cannot create a diagnostic report for DFS replication on a Microsoft Windows Server 2003 R2-based computer during the month of December"


    somebody shoot me - i swear my brain is exploding

    Tuesday, December 12, 2006 10:49 AM
  • Hi all!!!

    i only want to say that i was getting the same error:

    ex.Message = "Error HRESULT E_FAIL has been returned from a call to a COM component."

    but i resolved the problem, at least in my case ;-)... the problem was i didn' have 2 dll's needed by the object COM in the same folder the object was... when i copied the 2 dll's there, it just worked!!!!

    i hope this help somebody...


    Thursday, March 08, 2007 4:11 PM
  • Which dll's?


    I'm getting the same error just trying to load  a simple form.


    I'm using VS2010 x64 on Windows 7 (x64) with .net 4.

    Friday, September 24, 2010 3:35 PM
  • hi there, anyone with a solution, i am finding same problem, mine started when I migrated appl from VS2005 to VS2010 and NET Framework 4. Cannot even drag a control to a form.

    Pls someone assist.

    Sunday, September 26, 2010 12:25 PM