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

后端 未结 25 1020
情书的邮戳
情书的邮戳 2020-12-24 05:01

In Silverlight 4 app; what does this error mean?:

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

It

相关标签:
25条回答
  • 2020-12-24 05:57

    This error seems to be a 'catch-all' for errors that otherwise are not given a specific definition or tracing, especially those having to do with relatively external Xaml code.

    In my particular case, there seemed to be an issue with the namespaces. My UserControl is in its own namespace (creatively named "UserControls"). My Pages are in their own namespace ("Pages"). I wanted to reference an enum definition in the Pages namespace from within my UserControl, so I simply added a using statement: using MySolution.Pages;. Trivial enough, and I didn't want to believe that this was the problem. But when I removed that using statement and simply created the enum in my UserControls namespace, voila, no more HRESULT error and also, as an added bonus, my dependency properties defined in the UserControl, which otherwise were mysteriously not showing up in the Xaml intellisense, suddenly were there and ready to use.

    I suspect that underlying cause for this in my case was some sort of circular reference issue. And since there was no more specific error available to relate that information to me, it simply got shuffled into this HRESULT E_FAIL Com error.

    0 讨论(0)
  • 2020-12-24 05:59

    This is kind of an old question, but I figured I'd give my answer since I found this thread by Googling for the exact same problem.

    In my case, I'd copied some sample XAML from the web to get started with Silverlight Toolkit 4. That sample XAML contained a simple button with a click event handler that didn't relate to any handler that actually existed in my code behind. I didn't notice this simple problem at first, because the compiler didn't give me an error message, I just saw the "Error HRESULT E_FAIL has been returned from a call to a COM component" message above at runtime. It was only when I isolated my sample XAML by copying it into a brand new Silverlight application without any other content that the real underlying problem was revealed at compile-time.

    So, if you've got the same error message at runtime, my advice is to check your XAML carefully for any errors that you had expected should have been picked up at compile time, but which for some reason ended up as the runtime error noted above. In order to debug, you can do what I did and isolate the code that's causing the error in a standalone Silverlight app with no other content, and see if like me you get a more helpful error message to guide you.

    HTH.

    0 讨论(0)
  • 2020-12-24 06:04

    I had this error from problems with XAML. The strange thing was that I had missing resources used by Style and Margin attributes - which means the app runs fine, and even resharper only reports a 'hint'.

    Once I cleared up those problems my "Error HRESULT E_FAIL has been returned from a call to a COM component." disappeared. As others have said though, this is a vague error, very difficult to debug. In this case I have inherited a large project with 100's of VS and ReSharper messages with varying severity - missing StaticResource on Style attributes were not the first place I checked!

    0 讨论(0)
  • 2020-12-24 06:04

    Most of the times its difficult to see where exactly the problem is located especially in XAML. Another way to find out where its failing is to perform the following steps

    1. Copy the exception it shows in the output window of Visual Studio. example. System.Reflection.TargetInvocationException
    2. Click on Debug -> Exceptions. It shows up the exception list.
    3. Click on the "Add.." button.
    4. Paste the exception copied in the step 1 in the text box. Select "Common Language Runtime exceptions" in the drop down list.
    5. Click on "Ok" button. The selected exception will be highlighted. Make sure you check the checkbox against the exception. Click on "Ok" button again to close the dialog.
    6. Now run the application in debug mode. The application breaks when the exception occurs. Sometimes in the assembler mode as well.
    7. At this point in time you have two options,

      • Click on the View details of the exception screen shown. Dig into the inner exceptions until you get a clue from where its originating.

      • View the call stack to see which code of line of your is causing this exception. This will provide clues to resolve the issue.

    0 讨论(0)
  • 2020-12-24 06:05

    This is an old question but in my case, none of the above solutions worked. I was trying to update the NuGet packages in Visual Studio 2017 but I was getting the following Exception.

    update-package : Failed to add reference to 'System.Web.Razor'.
      Error HRESULT E_FAIL has been returned from a call to a COM component.
    

    In fact, other NuGet commands like restore-package were failing with similar exception message.

    I discovered a few assemblies were missing under the packages directory so I deleted the packages directory and returned back to the Visual Studio 2017. When I opened the solution it asked me to restore the packages and after that, I was able to update the packages.

    NOTE: Take a backup of package directory before deleting it.

    0 讨论(0)
  • 2020-12-24 06:06

    There are many solutions out there but this is the only solution that worked several times for me.It has been tried on VS2012 VS2013 and VS2015, I find it working equally good for all.Just follow steps bellow to fix this issue

    Step 1 : Close Visual Studio
    Step 2 : Delete *.csproj.user and *.suo files
    Step 3 : Reopen VS, and try to run project again in debug mode.

    NOTE : This situation occurs when multiple users working on same project with different VS versions .suo file is not supported for round-tripping between the two VS versions.It contains information about what settings current user has selected for his/hers VS working environment.

    0 讨论(0)
提交回复
热议问题