简体   繁体   中英

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

I am trying to create the com object using following code:

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

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)).

I have tried building the project with AnyPlatform ,X86, x64 bit platform and the used RegAsm for 32 and 64bit .

But still not able to get it working. I have verified in registry and the class and CLSID with GUID exists

在此处输入图片说明

It Started working , once I use codebase with Regasm

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). In development mode (Visual Studio) the error does not occur.

For me, the solution was in IIS -> Application Pool -> Advanced Settings -> Enable 32-Bit Applications: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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