简体   繁体   English

无法使用Activator.CreateInstance创建COM类的实例

[英]Unable to Create the instance of COM class using Activator.CreateInstance

I am trying to create the com object using following code: 我正在尝试使用以下代码创建com对象:

Type testlib = Type.GetTypeFromProgID("TestComApp.TestApp.TestClass");
dynamic comObj = Activator.CreateInstance(testlib);

But getting the error : 但是得到错误:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll mscorlib.dll中发生了类型为'System.Runtime.InteropServices.COMException'的未处理异常

Additional information: Retrieving the COM class factory for component with CLSID {FD909333-3CD0-477F-8A7E-B8045B0B84EC} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154REGDB_E_CLASSNOTREG)). 附加信息:由于以下错误,检索具有CLSID {FD909333-3CD0-477F-8A7E-B8045B0B84EC}的组件的COM类工厂失败:80040154未注册类(HRESULT的异常:0x80040154REGDB_E_CLASSNOTREG)。

I have tried building the project with AnyPlatform ,X86, x64 bit platform and the used RegAsm for 32 and 64bit . 我尝试使用AnyPlatform,X86,x64位平台以及用于32位和64位的RegAsm构建项目。

But still not able to get it working. 但是仍然无法使其正常工作。 I have verified in registry and the class and CLSID with GUID exists 我已经在注册表中进行了验证,并且存在带有GUID的类和CLSID

在此处输入图片说明

It Started working , once I use codebase with Regasm 一旦我在Regasm中使用codebase ,它就开始工作

cd "C:\Windows\Microsoft.NET\Framework\v4.0.30319"

regasm /codebase C:\DATA\TestComApp\TestComApp\bin\Debug\TestComApp.DLL

Earlier I was doing : 之前我在做:

cd "C:\Windows\Microsoft.NET\Framework\v4.0.30319"

regasm C:\DATA\TestComApp\TestComApp\bin\Debug\TestComApp.DLL

I had the same problem in a WCF project in production mode (in IIS). 在生产模式(在IIS中)的WCF项目中,我遇到了同样的问题。 In development mode (Visual Studio) the error does not occur. 在开发模式(Visual Studio)中,不会发生此错误。

For me, the solution was in IIS -> Application Pool -> Advanced Settings -> Enable 32-Bit Applications: 对我来说,解决方案是在IIS->应用程序池->高级设置->启用32位应用程序中: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM