Creating your own Regasm.exe

I do not know the exact internal implementation of regasm.exe, but one of the biggest limitations is that regasm.exe does not support assembly binding redirects.

This means a COM DLL can fail to load if it depends on other assemblies with different versions than the ones originally expected. You can see the regasm.exe errors in the console.

I am wondering if anyone has tried building their own lightweight alternative to regasm.exe.

From what I understand, the minimum implementation would likely involve:

  • Creating the required registry keys under:

    • HKEY_CLASSES_ROOT\CLSID{YourGuid}

    • HKEY_CLASSES_ROOT\ProgID

    • HKEY_CLASSES_ROOT\Interface{YourInterfaceGuid}

    • HKEY_CLASSES_ROOT\TypeLib{YourTypeLibGuid}

    • InprocServer32 entries pointing to mscoree.dll

  • Loading the target assembly with reflection

  • Finding COM-visible classes

  • Reading attributes like GuidAttribute, ProgIdAttribute, ComVisibleAttribute, ClassInterfaceAttribute, etc.

  • Locating methods marked with RegisterFunctionAttribute

  • Invoking the RegisterComFunction method manually after the registry entries are created

  • Potentially supporting custom assembly resolution logic or binding redirects during activation

Has anyone here attempted something like this, or found a good open-source implementation?