How to register .NET Assembly for COM Interop ?

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

Comments

  • Anonymous
    April 28, 2008
    PingBack from http://microsoftnews.askpcdoc.com/interop/how-to-register-net-assembly-for-com-interop-2

  • Anonymous
    August 06, 2012
    As I know DLL registration done by RegSvr32.exe. But I want to know how .Net dll registration done?

  • Anonymous
    March 12, 2014
    The information distinguishing the regasm locations for 32/64 bit machines was very useful to me. Many thanks!

  • Anonymous
    July 27, 2014
    What should i do if the "Register for COM Interop" option is disabled? (I'm using visual studio 2013). i have a problem with 64 bit vesrion. help me. Thanks

  • Anonymous
    January 30, 2015
    best article

  • Anonymous
    April 02, 2015
    Great to the point article! Thanks!