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条回答
兄弟一词,经得起流年.
2楼-- · 2020-02-17 08:02

In my situation:

I create a

class MyControl : ContentControl {
}

By default, the class is not public and XAML cannot load it and throw exception

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

Just change the scope of class to public and error disappear.

Hope this help.

PS. Microsoft should provide more on information than just throw a mystery error message without any stack trace.

查看更多
孤傲高冷的网名
3楼-- · 2020-02-17 08:02

The IIS App Pool has to run as an account that has query access to the Team Foundation Server. This fixes the problem for me.

查看更多
老娘就宠你
4楼-- · 2020-02-17 08:04

I had this exception and went nuts. I would advice you check if you had recently installed a component that had possible conflicting namespace items. In my case I installed the windows phone tool-kit which had items that were similarly named with the stock tool kit on windows phone. Asap I uninstalled this from the Nuget package manager, all was back to normal.

查看更多
【Aperson】
5楼-- · 2020-02-17 08:05

My problem was a missing Style. I had overridden a control template with a custom brush like so:

<Style x:Key="MyCustomStyle" TargetType="Thumb">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Thumb">
                ....
                <TextBlock Foreground="{StaticResource MyCustomBrush}"

and was missing my definition of MyCustomBrush, like so:

<SolidColorBrush x:Key="MyCustomBrush" Color="#FFAC0909"/>

and then BOOM, app didn't startup and I got that COM error message.

查看更多
Melony?
6楼-- · 2020-02-17 08:05

For me, I narrowed it down to a SplitButton control that I downloaded off CodePlex ages ago. I had upgraded the solution from Silverlight 4 to Silverlight 5 and got slammed with this error. I was able to narrow it down by commenting out the XAML to all controls then uncommented it back in one by one until the error appreared again:

System.Reflection.TargetInvocationException was unhandled by user code
  Message=Exception has been thrown by the target of an invocation.
  StackTrace:
       at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       at System.Delegate.DynamicInvokeImpl(Object[] args)
       at System.Delegate.DynamicInvoke(Object[] args)
       at Homexaml_3.BindingOperation(Object BindingState, Int32 , Action )
  InnerException: 
       Message=Error HRESULT E_FAIL has been returned from a call to a COM component.
       StackTrace:
            at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
            at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)
            at System.Windows.UIElement.Measure(Size availableSize)

What fixed it was manually removing the outdated references System.Windows.Control and System.Windows.Controls.Toolkit then re-added them from the Silverlight 5 SDK folder.

Hope it helps someone (and helps me!) if it happens again a few months down the road.

查看更多
仙女界的扛把子
7楼-- · 2020-02-17 08: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.

查看更多
登录 后发表回答