Share via


Applying Version-Dependent Attributes

If you are using the .NET Framework version 1.1 and later, you can apply design-time attributes to managed source code for proper activation of types registered in the Windows registry. This topic describes when to apply the ComCompatibleVersionAttribute and TypeLibVersionAttribute attributes.

Generated vs. Fixed GUIDs

The Type Library Exporter (Tlbexp.exe) and the Assembly Registration Tool (Regasm.exe) with the /tlb option generate class identifiers (CLSIDs) based on the version number of an assembly exported for use by COM. Each new version of an assembly that you export contains CLSIDs that are unique for that assembly version. A COM application uses the CLSID to identify a class when invoking the CoCreateInstance method.

This behavior is useful when a new assembly version is incompatible with previous versions. For example, if one or more types are removed from the new assembly, the old and new versions are incompatible.

Note

Unlike CLSIDs, programmatic identifiers (ProgIDs) do not change with each new version of an assembly. You should apply the ProgIdAttribute to manually change a ProgID when producing a new, incompatible assembly.

However, many assemblies are compatible with earlier versions and their developers expect applications to use the latest version. By preserving the same CLSIDs across multiple assembly versions (using fixed GUIDs), existing COM applications can consume types in the new version of an assembly without requiring that the old assembly be available and without recompiling.

ComCompatibleVersionAttribute forces all CLSIDs in the current assembly version to be the same as the CLSIDs in an earlier version. For additional information about applying this attribute, see the ComCompatibleVersionAttribute reference documentation.

Type Library Versions

A type library version number contains the major and minor numbers of the assembly used to produce it. In contrast, an assembly version number has four parts. Two completely different assembly versions (1.0.0.0 and 1.2.500.0) automatically produce different type library versions (1.0 and 1.2); however, closer incrementing versions (1.2.0.0 and 1.2.500.0) both produce the same type library version (1.2) when exported for use by COM.

TypeLibraryVersionAttribute enables you to specify a type library version number explicitly in managed source code. For additional information on using this attribute, see the TypeLibVersionAttribute reference documentation.

See Also

Concepts

Runtime Initialization from a COM Application

Version-Dependent Registry Keys

Configuring a COM Application for Side-by-Side Execution

COM Components and Side-by-Side Execution

Other Resources

Side-by-Side Execution for COM Interop