다음을 통해 공유


Version-Dependent Registry Keys 

Most managed assemblies must be registered in the Windows registry for use by COM. Assemblies using registration-free COM interop are exempt from this requirement.

You can register an assembly by using the Assembly Registration Tool (Regasm.exe) or methods exposed by the RegistrationServices class. Each mechanism creates version-dependent registry keys that allow multiple versions of the same assembly to run side-by-side on a computer.

This topic describes how Regasm.exe adds and removes COM-enabling registry entries. If you are writing a custom installation program, this topic can assist you in understanding the registration requirements of side-by-side execution for COM interop.

Registry Layout for Version-Dependent Keys

When you initially register an assembly, Regasm.exe creates a set of top-level keys for each class in the assembly and adds a subkey under HKEY CLASSES\ROOT\CLSID\{}\InprocServer32 key to uniquely identify the assembly version. The following registry layout shows the subkey for className version 1.0.0.0.

CLSID\{}
@="namespaceName.className"
CLSID\{}\InprocServer32
@="mscoree.dll"
ThreadingModel = "Both" 
Class="namespaceName.className"
Assembly="name, Version=2.0.0.0, Culture=neutral, PublicKeyToken="
RuntimeVersion="v1.0.3705"
1.0.0.0
   Class="namespaceName.className"
   Assembly="name, Version=1.0.0.0, Culture=neutral, PublicKeyToken="
          RuntimeVersion="v1.0.3705"
CLSID\{}\ProgId
@="namespaceName.className"
CLSID\{}\ImplementedCategories\{guid}

As you register subsequent versions of the assembly, Regasm.exe adds a version-dependent subkey for each new version. All versions of the same assembly share the top-level keys (shown in the previous registry layout). The following partial layout shows subkeys 1.0.0.0 and 2.0.0.0 of the same assembly.

1.0.0.0
   Class="namespaceName.className"
   Assembly="name, Version=1.0.0.0, Culture=neutral, PublicKeyToken="
          RuntimeVersion="v1.0.3705"
2.0.0.0
   Class="namespaceName.className"
   Assembly="name, Version=2.0.0.0, Culture=neutral, PublicKeyToken="
          RuntimeVersion="v1.1.5000"

Version-Dependent Key Removal

Regasm.exe removes only the version-dependent subkey when you uninstall an assembly version. For example, if you uninstalled className version 1.0.0.0, Regasm.exe removes the 1.0.0.0 subkey but retains all top-level keys and the 2.0.0.0 subkey.

CLSID\{}
   @="namespaceName.className"
CLSID\{}\InprocServer32
   @="mscoree.dll"
ThreadingModel = "Both" 
Class="namespaceName.className"
Assembly="name, Version=2.0.0.0, Culture=neutral, PublicKeyToken="
RuntimeVersion="v1.0.3705"
Version
2.0.0.0
   Class="namespaceName.className"
   Assembly="name, Version=2.0.0.0, Culture=neutral, PublicKeyToken="
          RuntimeVersion="v1.1.5500"
CLSID\{}\ProgId
   @="namespaceName.className"
CLSID\{}\ImplementedCategories\{guid}

When you uninstall the last version of an assembly, Regasm.exe removes all version-dependent subkeys. It also removes the top-level keys associated with the assembly from the registry.

See Also

Concepts

Runtime Initialization from a COM Application
Configuring a COM Application for Side-By-Side Execution
Applying Version-Dependent Attributes
COM Components and Side-By-Side Execution

Other Resources

Side-By-Side Execution for COM Interop