C# HRESULT 异常:0x80004002 (E_NOINTERFACE)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9788135/
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
Exception from HRESULT: 0x80004002 (E_NOINTERFACE)
提问by Michael
I'm in charge of the maintenance of a C# application (VS 2005). This C# applications calls a dll ("mydll.dll"). I needed to make a few changes on the dll in question.
我负责维护一个 C# 应用程序 (VS 2005)。这个 C# 应用程序调用一个 dll(“mydll.dll”)。我需要对有问题的 dll 进行一些更改。
I have the file "mydll.vbp" that was written in Visual Basic 6.0. I made my changes in Visual Studio and, then, "made "mydll"" from the Visual Basic interface.
我有用 Visual Basic 6.0 编写的文件“mydll.vbp”。我在 Visual Studio 中进行了更改,然后从 Visual Basic 界面“制作了“mydll”。
The problem is that, now, at each time I try to instance a class from "mydll.dll" in debbuger mode in C#, I have the following "InvalidCastException"
问题是,现在,每次我尝试在 C# 的调试器模式下从“mydll.dll”实例化一个类时,我都会遇到以下“InvalidCastException”
Unable to cast COM object of type mydll.ClassFrommydll to interface type mydll._ClassFrommydll'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{384FB79F-B636-4655-9441-8222692AB8AE}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
无法将 mydll.ClassFrommydll 类型的 COM 对象转换为接口类型 mydll._ClassFrommydll'。此操作失败,因为 IID 为“{384FB79F-B636-4655-9441-8222692AB8AE}”的接口的 COM 组件上的 QueryInterface 调用因以下错误而失败:不支持此类接口(来自 HRESULT 的异常:0x80004002 (E_NOINTERFACE)) .
I tried to re-reference the dll in question ... but that does not change anything.
我试图重新引用有问题的 dll ......但这并没有改变任何东西。
Any idea on what it could come from ?
知道它可能来自什么吗?
Many many thanks to all of yopu who can help. Have been stuck with this problem for days now. Start to feel the pressure ...
非常感谢所有可以提供帮助的 yopu。已经被这个问题困扰了好几天了。开始感受到压力...
回答by Rumplin
Remove all GUIDs and "ComVisible" attributes from the class, then switch the [assembly: ComVisible(true)] attribute in the AssemblyInfo-File to 'true'.
从类中删除所有 GUID 和“ComVisible”属性,然后将 AssemblyInfo 文件中的 [assembly: ComVisible(true)] 属性切换为“true”。
回答by Saddam Mohsen
mark the main class [STAThread] and your problem will be solved
标记主类[STAThread],你的问题就解决了
回答by Ashetynw
I ran into this exact problem using the IBM Dll's.
我使用 IBM Dll 遇到了这个确切的问题。
[STAThread]
static void Main(string[] args)
{
}
Fixed the issue for me with all COM interfaces being usable and the exception cleared
为我修复了所有 COM 接口都可用且异常已清除的问题

