10

In a VC++ project, I am trying to create an instance (via COM) of a C# class contained within a C# project.

Facts

  • Both the C# and C++ projects are compiled using .NET 4.0
  • The C# .dll is being registered using regasm /codebase "CSharpProjectName.dll"", and windows command prompt reports, "Types registered successfully."
  • In the c++ project, I attempt to create an instance of a class in the C# project, but I get an HRESULT of 0x80040154 - class not registered

Here is an example of my attempt to create an instance of the .NET object from the C# .dll. The concrete class I am trying to instantiate is called Employee, which for the sake of presenting my question simply, implements the IPerson interface:

    CSharpProjectName::IPersonPtr pPersonPtr;
    HRESULT hr = pPersonPtr.CreateInstance(CSharpProjectName::CLSID_Employee);

Why am I getting a "class not registered" error even though I registered the c# .dll using "regasm /codebase" and confirmed existence of the key in the registry?

Any help would greatly be appreciated. Thanks!

1
  • 1
    I have this exact problem! Commented Mar 17, 2016 at 15:43

3 Answers 3

10

I've had that problem in the past and it was due to both processes not being 32 or 64 bit. If you are running a 32-bit OS, you can stop reading now because what I say doesn't apply.

Use regedit to try and find your ProgIds and CLSIDs in the registry. If your C++ project is 32-bit, make sure that your C# classes were registered to the 32-bit hive--HKEY_CLASSES_ROOT\Wow6432Node. If your C++ project is 64-bit, make sure that your C# classes were registered to the 64-bit hive--HKEY_CLASSES_ROOT.

If you need to register to the 64-bit hive, you may need to call the version of RegAsm.exe under c:\windows\microsoft.net\framework64...

The other possibility for things to go wrong is that you might need to run the .NET 4.0 version of regasm.exe. If you just type "regasm" in the command line, it will give you the version of regasm you are running. You might need to type the full path of .NET 4.0 version of regasm--found at c:\windows\microsoft.net\framework\v4.0.3019\regasm.exe.

Sign up to request clarification or add additional context in comments.

2 Comments

that was it! I was using the v2.0... regasm rather than v4.0.... regasm. Thanks a lot!
so, if the required CLID is 91493441-5A91-11CF-8700-00AA0060263B, and after trying search cannot to find it between the current registries (regedit)?
1

Have you tried the /tlb option? Try that, and then

#import "your_tlb_file_lol.tlb" no_namespace

I think the other option might be to gac the assembly and then regasm it.

1 Comment

I tried that using #import "CSharpProjectName.tlb" named_guids raw_interfaces_only. Still didn't work...
0

Try to leave your project in 32 bits because you know your project, creating in Any CPU an active component that runs at 32 with a registry error, so change the build to 32 or preferably to 32.

You Too register you dll with regsvr32

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.