locked
"Error HRESULT E_FAIL has been returned from a call to a com component" while executing a VB Macro. RRS feed

  • Question

  • Hi,

    I recorded a macro which does the following:
    1. Opens a C# solution.
    2. Edits a file.
    3. Save.
    4. Build the selected project.
    5. Further edit the file (or any other file).
    6. Save.
    7. Build the selected project again.

    While debug the macro, I can see that for some reason, in the second time the selected project is being built, I'm getting the error:

    "Error HRESULT E_FAIL has been returned from a call to a com component"

    (The code line is: DTE.ExecuteCommand("Build.BuildSelection") )

    Thanks
    Thursday, May 7, 2009 5:03 PM

Answers

  • Well that's certainly easy to reproduce :-)

    I think you'll need to wait until the first build completes before you attempt to do it again.

    As an alternative, you could use SolutionBuild.Build and pass TRUE for the WaitForBuiltToFinish argument. For example:


    DTE.Solution.SolutionBuild.Build(True)
    DTE.Solution.SolutionBuild.Build(
    True)

     

    Sincerely,


    Ed Dore
    Sunday, May 10, 2009 4:03 AM

All replies

  • Are the selections in the Solution Explorer still valid? Commands like these are enabled and disabled based on the currently selected item(s) in the Solution Explorer. This might be why you are seeing the macro fail on the 2nd invocation.

    Sincerely,


    Ed Dore
    Thursday, May 7, 2009 6:39 PM
  • Yes,

    I also tried to select the items in the Solution Explorer before the next build. It didn't help.
    Other suggestions ?

    Thanks
    Thursday, May 7, 2009 7:23 PM
  • Can you post the macro code, with specific steps to reproduce the problem?

    Usually, that error pops up with a COM call fails to return an S_OK value. The command is failing, but we can't really tell why. 

    It would be interesting to see this same code run from an add-in instead. If the problem still occurs with the add-in, it might be easier to debug.

    Sincerely,
    Ed Dore
    Friday, May 8, 2009 9:07 PM
  • Here is the code of the Macro:

    Option Strict Off
    Option Explicit Off
    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports EnvDTE90
    Imports System.Diagnostics

    Public Module RecordingModule


        Sub TemporaryMacro()
            DTE.ExecuteCommand("Build.BuildSelection")
            DTE.ExecuteCommand("Build.BuildSelection")
        End Sub
    End Module


    Thanks

    Sunday, May 10, 2009 12:29 AM
  • Well that's certainly easy to reproduce :-)

    I think you'll need to wait until the first build completes before you attempt to do it again.

    As an alternative, you could use SolutionBuild.Build and pass TRUE for the WaitForBuiltToFinish argument. For example:


    DTE.Solution.SolutionBuild.Build(True)
    DTE.Solution.SolutionBuild.Build(
    True)

     

    Sincerely,


    Ed Dore
    Sunday, May 10, 2009 4:03 AM
  • Great!
    Thanks!!!
    Sunday, May 10, 2009 9:32 PM