Reg-free COM allows using a copy-deployment for applications depending on a COM/ActiveX component, which means that the COM/ActiveX component can be used without prior registration. The same process also can be used for auto-registering .Net-based components compiled to expose themselves to COM/ActiveX client applications using COM Interop.

The general procedure is identical to that outlined in the article explaining the copy deployment of ActiveX controls:
  • The manifest of the client application is used to define the dependencies of the .EXE on a certain .Net component
  • A manifest defined for the component DLL (.Net assembly) is used by the loader to determine whether the component(s) in the DLL satisfy any of the client dependencies. The component manifest also contains the information required by the OS to automatically register the .Net component if it isn't already registered when the client application starts.

Differences when using Reg-free COM with .Net components​

  1. Unlike an ActiveX control which resides in a regular DLL or .OCX file, a .Net component is implemented in a so-called .Net assembly. Although .Net assemblies usually also have a .DLL extension, references in .Net applications are defined via the assembly identity (name) instead of the .DLL file name. With regard to Reg-free COM, this means that the dependency in the application manifest also must be defined using the assembly name (and not the .DLL file name!).
  2. Because the application manifest declares a dependency to an assembly instead of to a file, the component manifest must be defined in the resource of the .Net DLL. The manifest cannot simply be installed side-by-side with the .DLL file as in the COM/ActiveX case.
  3. Since the .Net component is accessed via the COM Interop layer (ActiveX bridge), instead of being accessed directly, the method of registering the component for COM differs slightly. Instead of defining COM-specific types using "comClass" XML nodes in the component manifest, "clrClass" nodes must be used in the case of a .Net component.

Example: Dependency to a .Net assembly named "AlaskaComInteropTest"​


Note the dependency on a .Net assembly name instead of a .DLL file!

Application manifest file (runner.exe.manifest):

XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">

<assemblyIdentity
  type="win32"
  name="runner.exe"
  version="1.0.0.0" />
  <dependency>
          <dependentAssembly>
              <assemblyIdentity
                  type="win32"
                  name="AlaskaComInteropTest"
                  version="0.0.0.0" />
          </dependentAssembly>
  </dependency>
</assembly>

Component manifest file (incorporated in .Net assembly "AlaskaComInteropTest" located in "alaskacominteroptest.dll"):

XML:
<?xml version="1.0" encoding="utf-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity
    name="AlaskaComInteropTest"
    version="0.0.0.0"
    type="win32"/>

 <clrClass clsid="{241A96B9-EA5E-3D50-84C3-A5915A27256D}"
          progid="AlaskaComInteropTest.ParameterTest"
          threadingModel="Both"
          name="AlaskaComInteropTest.ParameterTest"
          runtimeVersion="v4.0.30319">
 </clrClass>

 <clrClass clsid="{DE547EC7-3030-3E74-B008-44EF269FA539}"
          progid="AlaskaComInteropTest.ArrayTest"
          threadingModel="Both"
          name="AlaskaComInteropTest.ArrayTest"
          runtimeVersion="v4.0.30319">
 </clrClass>

<file name="AlaskaComInteropTest.dll">
   <typelib tlbid="{1B570662-FB21-3E5C-BDBA-029434820ED1}" version="1.0"/>
</file>
</assembly>

Preparing a .Net component for usage with COM Interop​


A .Net component must be compiled in a specific way in order to be usable with COM interop. This involves, among other things, making the component class visible to COM using the "ComVisible" attribute. This step must be done by the component creator. Since the component manifest must be a part of the resulting binary (.DLL), the same is true for the manifest file. Please refer to the reference section to learn more about the abovementioned steps.

References​

- Exposing .Net components to COM
- Creating and modifying component manifests using mt.exe
  • Like
Reactions: Osvaldo Ramirez