visual-studio 调用 COM 组件时返回了错误 HRESULT E_FAIL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4210405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error HRESULT E_FAIL has been returned from a call to a COM component
提问by pencilslate
In Silverlight 4 app; what does this error mean?:
在 Silverlight 4 应用程序中;这个错误是什么意思?:
"Error HRESULT E_FAIL has been returned from a call to a COM component."
“错误 HRESULT E_FAIL 已从对 COM 组件的调用返回。”
It's a very generic error. The VS debugger doesn't point to the exact location of the error when debugging.
这是一个非常普遍的错误。VS 调试器在调试时不会指向错误的确切位置。
回答by Rachel
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.
就我而言,我从 Web 复制了一些示例 XAML 以开始使用 Silverlight Toolkit 4。该示例 XAML 包含一个带有单击事件处理程序的简单按钮,该按钮与实际存在于我的代码中的任何处理程序无关。一开始我没有注意到这个简单的问题,因为编译器没有给我错误信息,我只是在运行时看到上面的“Error HRESULT E_FAIL has been returned from a call to a COM component”信息。只有当我通过将我的示例 XAML 复制到一个没有任何其他内容的全新 Silverlight 应用程序来隔离它时,才在编译时揭示了真正的潜在问题。
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.
因此,如果您在运行时收到相同的错误消息,我的建议是仔细检查您的 XAML 是否有任何您预期应该在编译时发现的错误,但由于某种原因,这些错误以运行时错误告终多于。为了调试,您可以执行我所做的操作,并在没有其他内容的独立 Silverlight 应用程序中隔离导致错误的代码,看看您是否像我一样获得更有用的错误消息来指导您。
HTH.
哈。
回答by Malik Khalil
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
有很多解决方案,但这是唯一对我有用过几次的解决方案。它已经在 VS2012 VS2013 和 VS2015 上尝试过,我发现它对所有人都一样好。只需按照下面的步骤来解决这个问题
Step 1 : Close Visual Studio
Step 2 : Delete *.csproj.userand *.suofiles
Step 3 : Reopen VS, and try to run project again in debug mode.
步骤 1:关闭 Visual Studio
步骤 2:删除*.csproj.user和*.suo文件
步骤 3:重新打开 VS,并尝试在调试模式下再次运行项目。
NOTE : This situation occurs when multiple users working on same projectwith different VS versions
.suofile 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.
注意:这种情况发生在多个用户使用不同 VS 版本文件在同一项目上工作时,不支持在两个 VS 版本之间进行往返。它包含有关当前用户为他/她的 VS 工作环境选择的设置的信息。
.suo
回答by greensuisse
In my situation:
在我的情况下:
I create a
我创建一个
class MyControl : ContentControl {
}
By default, the class is not public and XAML cannot load it and throw exception
默认情况下,该类不是公共的,XAML 无法加载它并抛出异常
Error HRESULT E_FAIL has been returned from a call to a COM component
调用 COM 组件时返回了错误 HRESULT E_FAIL
Just change the scope of class to public and error disappear.
只需将类的范围更改为 public,错误就会消失。
Hope this help.
希望这有帮助。
PS. Microsoft should provide more on information than just throw a mystery error message without any stack trace.
附注。微软应该提供更多的信息,而不仅仅是抛出一个没有任何堆栈跟踪的神秘错误消息。
回答by orellabac
I also had this error and I found that this problem is related to not have added all requiered assemblies to your project. In my case I was using a UserControl with a depency with the Silverlight Toolkit and I havent added this reference. I just added the reference and everything solved :)
我也有这个错误,我发现这个问题与没有将所有需要的程序集添加到您的项目中有关。在我的情况下,我使用的是与 Silverlight Toolkit 相关的 UserControl,但我没有添加此引用。我刚刚添加了参考,一切都解决了:)
回答by Luke Woodward
Here's one way to generate this error, which I stumbled upon today. We have the following button in XAML:
这是我今天偶然发现的一种产生此错误的方法。我们在 XAML 中有以下按钮:
<Button x:Name="button" Click="Button_Click" Content="Click me" />
The event handler that handles the button's Clickevent is as follows:
处理按钮Click事件的事件处理器如下:
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 NaNwith PositiveInfinityor NegativeInfinity.
当我单击按钮时,出现上述错误。如果我NaN用PositiveInfinityor替换,也会出现同样的错误NegativeInfinity。
Interestingly, I get a different error message if the first parameter of the Thicknessconstructor contains the NaNinstead of the second.
有趣的是,如果Thickness构造函数的第一个参数包含NaN而不是第二个,我会收到不同的错误消息。
回答by Ben Parsons
I had this error from problems with XAML. The strange thing was that I had missing resources used by Styleand Marginattributes - which means the app runs fine, and even resharper only reports a 'hint'.
我因 XAML 问题而出现此错误。奇怪的是,我缺少使用的资源Style和Margin属性——这意味着应用程序运行良好,甚至 resharper 也只报告一个“提示”。
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 StaticResourceon Styleattributes were not the first place I checked!
一旦我清除了这些问题,我的“错误 HRESULT E_FAIL 已从对 COM 组件的调用返回”。消失了。正如其他人所说,这是一个模糊的错误,很难调试。在这种情况下,我继承了一个大项目,100个VS和ReSharper的消息轻重不一-失踪StaticResource的Style属性不是我签的第一名!
回答by IsolatedStorage
I had this error using the current SL4 Telerik controls. A similar issue has been reported herewith a solution ... of sorts. The problem seems to be with the way Expression Blend manages the cache of controls.
我在使用当前的 SL4 Telerik 控件时遇到了这个错误。一个类似的问题已经在这里报告了一个解决方案......各种各样的。问题似乎与 Expression Blend 管理控件缓存的方式有关。
回答by ilke.uygun
I had this error in my xaml page and there were no syntax errors. Cleaning and re-building the project solved my issue. fyi...
我的 xaml 页面中有此错误,并且没有语法错误。清理和重建项目解决了我的问题。供参考...
回答by abder
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.
IIS 应用程序池必须作为对 Team Foundation Server 具有查询访问权限的帐户运行。这为我解决了问题。
回答by Rocklan
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:
并且缺少我对 MyCustomBrush 的定义,如下所示:
<SolidColorBrush x:Key="MyCustomBrush" Color="#FFAC0909"/>
and then BOOM, app didn't startup and I got that COM error message.
然后 BOOM,应用程序没有启动,我收到了那个 COM 错误消息。

