Register a C#/VB.NET COM dll programmatically

Stefan Steiger picture Stefan Steiger · Mar 4, 2010 · Viewed 15.5k times · Source

Question: I have a .NET dll which I use from a C++ program. Now I have to register the dll programmatically on a deployment computer.

How do I do that (programmatically! not using regasm)? I remember, when I once called a VB6 dll from a C++ dll, I had to use DllRegisterServer and DllUnregisterServer.

Is that still so with a .NET dll?
It seems I have to somehow add the dllregisterserver function to the .NET dll.

Answer

Stefan Steiger picture Stefan Steiger · Mar 4, 2010

YUK, .NET dlls don't have DllRegisterServer, so you have to write a .NET installer, executing this somewhere:

Assembly asm = Assembly.LoadFile (@"c:\temp\ImageConverter.dll");
RegistrationServices regAsm = new RegistrationServices();
bool bResult = regAsm.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase);