COM 服务器的托管客户端抛出 InvalidCastException
我注册了非常简单的本机 COM 服务器,并且我的本机 COM 客户端可以成功调用 COM 方法。但是,我的托管 COM 客户端抛出以下错误:
无法将“DevicesLib.MyComClass”类型的 COM 对象强制转换为“DevicesLib.IMyComInterface”接口类型。此操作失败,因为对 IID 为“{503DDA5C-F8A2-4273-810F-3855EE0F2B78}”的接口的 COM 组件上的 QueryInterface 调用由于以下错误而失败:不支持此类接口(HRESULT 异常:0x80004002 (E_NOINTERFACE)) 。
我使用 tlbimp.exe 生成延迟签名的互操作 dll。我的操作系统是 64 位 Windows Server 2008 R2。
有什么想法吗?
谢谢 莱昂
I registered my very simple native COM server and my native COM client can call the COM method successfully. However, my managed COM client threw below error:
Unable to cast COM object of type 'DevicesLib.MyComClass' to interface type 'DevicesLib.IMyComInterface'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{503DDA5C-F8A2-4273-810F-3855EE0F2B78}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
I used tlbimp.exe to generate a delay signed interop dll. My OS is 64 bit windows server 2008 R2.
Any idea?
Thanks
Leon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我为 main() 装饰 [STAThreadAttribute] 后,它起作用了。
After I decorate [STAThreadAttribute] for the main(), it worked.
您的接口不得注册用于封送。您的 CoClass 可能已注册为需要 STA。如果没有 STAThreadAttribute,则主线程是 MTA。创建 COM 对象会将其放入不同的 STA 线程中,然后尝试将接口指针封送回您。
Your interface must not be registered for marshaling. Your CoClass is probably registered as requiring an STA. Without the STAThreadAttribute, the main thread is MTA. Creating the COM object puts it in a different STA thread, and then tries to marshal the interface pointer back to you.