Error HRESULT E_FAIL has been returned from a call

2020-02-17 07:03发布

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

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

It's a very generic error. The VS debugger doesn't point to the exact location of the error when debugging.

24条回答
一纸荒年 Trace。
2楼-- · 2020-02-17 07:55

I had this error using the current SL4 Telerik controls. A similar issue has been reported here with a solution ... of sorts. The problem seems to be with the way Expression Blend manages the cache of controls.

查看更多
地球回转人心会变
3楼-- · 2020-02-17 07:56

Most of the reason of this problem related dependency propertied on component design. You just face off this problem on design.

Soulution is easy but takes time :) Clean project and rebuild all. When you enter the desing again you should see everything is fine!

I hope this helps!

If you see this exception recently, please try to re-install silverlight sdk4.

查看更多
乱世女痞
4楼-- · 2020-02-17 07:57

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!

查看更多
Lonely孤独者°
5楼-- · 2020-02-17 07:57

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.

查看更多
地球回转人心会变
6楼-- · 2020-02-17 07:58

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.

查看更多
Explosion°爆炸
7楼-- · 2020-02-17 08:00

Here's one way to generate this error, which I stumbled upon today. We have the following button in XAML:

    <Button x:Name="button" Click="Button_Click" Content="Click me" />

The event handler that handles the button's Click event is as follows:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        button.Margin = new Thickness(0, double.NaN, 0, 0);
    }

When I click on the button I get the aforementioned error. The same error arises if I replace NaN with PositiveInfinity or NegativeInfinity.

Interestingly, I get a different error message if the first parameter of the Thickness constructor contains the NaN instead of the second.

查看更多
登录 后发表回答