How to register .NET Assembly for COM Interop ?

How to register .NET Assembly for COM Interop ?

  • Comments 4

Do you want to use your .NET DLL (assembly) from VB6 or C++ application (native code) ? Yes, you can do that using COM Interop. As per COM rules, you need to get your assembly registered on system (in Registry, yes, thats how COM works!).

To get an assembly registered on system, you can use regasm utility that comes with .net framework.

If you have .NET Framework 2.0 installed, regasm would be in following path (assuming you have 32-bit OS)
C:\windows\microsoft.net\Framework\v2.0.50727\regasm.exe

If you have 64-bit OS as well as .NET framework installed, you should find 32bit version of regasm in,
C:\windows\microsoft.net\Framework\v2.0.50727\regasm.exe

and 64 bit version of regasm should be in,
C:\windows\microsoft.net\Framework64\v2.0.50727\regasm.exe

More on regasm and its command line options is described here.

If you are developing project in Visual Studio, there is option to register your assembly with COM Interop in Project Properties (Right click on project and choose properties), Go to Build tab, There is an option for "Register for COM Interop". (Basically what it does is, it calls regasm after DLL is built!)

image

 

There are two options while registering the assembly for COM Interop,

  • Put your assembly in GAC.
    • If you put your assembly in GAC, you don't have to use /codebase command line switch with regasm, because application will be able to find the assembly using default probing mechanisms.
  • Assembly is not in GAC.
    • Its advisable to use /codebase command line switch when you dont have your assembly in GAC because that will add absolute path for your assembly in registry so that COM client (your native application which uses .NET assembly) can find it.
    • Following is what will be written in case if you choose to use /codebase option while registering. (notice the CodeBase key).

image

Stay tuned.. Wave

Leave a Comment
  • Please add 3 and 3 and type the answer here:
  • Post
Page 1 of 1 (4 items)