Search code examples
c#.netcomregasm

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

enter image description here


Solution

  • 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