Type Equivalence and Embedded Interop Types
Beginning with the .NET Framework 4, the common language runtime supports embedding type information for COM types directly into managed assemblies, instead of requiring the managed assemblies to obtain type information for COM types from interop assemblies. Because the embedded type information includes only the types and members that are actually used by a managed assembly, two managed assemblies might have very different views of the same COM type. Each managed assembly has a different Type object to represent its view of the COM type. The common language runtime supports type equivalence between these different views for interfaces, structures, enumerations, and delegates.
Type equivalence means that a COM object that is passed from one managed assembly to another can be cast to the appropriate managed type in the receiving assembly.
Type equivalence and embedded interop types simplify the deployment of applications and add-ins that use COM components, because it is not necessary to deploy interop assemblies with the applications. Developers of shared COM components still have to create primary interop assemblies (PIAs) if they want their components to be used by earlier versions of the .NET Framework.
Equivalence of COM types is supported for interfaces, structures, enumerations, and delegates. COM types qualify as equivalent if all of the following are true:
The types are both interfaces, or both structures, or both enumerations, or both delegates.
The types have the same identity, as described in the next section.
Both types are eligible for type equivalence, as described in the Marking COM Types for Type Equivalence section.
Two types are determined to have the same identity when their scopes and identities match, in other words, if they each have the TypeIdentifierAttribute attribute, and the two attributes have matching Scope and Identifier properties. The comparison for Scope is case-insensitive.
If a type does not have the TypeIdentifierAttribute attribute, or if it has a TypeIdentifierAttribute attribute that does not specify scope and identifier, the type can still be considered for equivalence as follows:
For interfaces, the value of the GuidAttribute is used instead of the TypeIdentifierAttribute.Scope property, and the Type.FullName property (that is, the type name, including the namespace) is used instead of the TypeIdentifierAttribute.Identifier property.
For structures, enumerations, and delegates, the GuidAttribute of the containing assembly is used instead of the Scope property, and the Type.FullName property is used instead of the Identifier property.
Marking COM Types for Type Equivalence
You can mark a type as eligible for type equivalence in two ways:
Apply the TypeIdentifierAttribute attribute to the type.
Make the type a COM import type. An interface is a COM import type if it has the ComImportAttribute attribute. An interface, structure, enumeration, or delegate is a COM import type if the assembly in which it is defined has the ImportedFromTypeLibAttribute attribute.