How do I properly register a .NET assembly during an installation without calling RegAsm?

Refresh

February 2019

Views

1.1k time

1

I have a .NET COM-visible out-of-process server, let's call it Server.exe. I need to be able to register it on systems that may have different versions of the .NET framework installed, so I'd like to avoid calling RegAsm by it's full name (which tends to contain the version number of the .NET framework).

I've been trying to get it working by exporting a registry patch and importing it with:

regasm /regfile:foo.reg Server.exe
reg import foo.reg

However, applying the patch does not properly register the component. I'm able to register it using regasm directly. I'm an admin. What is regasm doing that it's not writing to the registry patch?

Wug

1 answers

4

It's because RegAsm is broken and does not behave consistently between regular registration and deferred registration via registry patching, and due to its quantum nature, it will produce distinct registry entries depending on which behavior is requested. Use of RegAsm to simulate quantum computations between the superposition of in-process and out-of-process servers has yet to be explored.

To solve this issue:

  1. Use RegAsm /regfile:foo.reg Server.exe to produce a registry patch.
  2. Use RegAsm /register Server.exe to properly register the type.
  3. Open foo.reg in notepad. Several of the keys specified in foo.reg will have a path of the format: HKEY_CLASSES_ROOT\CLSID\{YOUR-CLSID}. Open regedit and locate this key.
  4. Export this key as bar.reg and open it in notepad.
  5. Copy all entries from bar.reg to foo.reg, and remove any existing entries from foo.reg that add values to any part of HKEY_CLASSES_ROOT\CLSID\{YOUR-CLSID}.

    • Keep in mind that if you are on a 64 bit system, registry redirection will likely mean this key is stored in HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{YOUR-CLSID} instead of HKEY_CLASSES_ROOT\CLSID\{YOUR-CLSID}. To ensure consistent deployment over both 32 and 64 bit systems, remove Wow6432Node\ from the path (leaving the paths as they would look on a 32 bit system) and apply them to the registry using reg import foo.reg /reg:32. /reg:32 is a semi-documented switch which should work on both 32 and 64 bit versions of windows which will enable registry reflection even on 64 bit versions of reg, thus making sure the entries are installed in the right place.
Wug