Share via


How to: Create Primary Interop Assemblies Manually 

A less frequently used approach for producing a type library involves creating a primary interop assembly manually in source code by using a language that is compliant with the Common Language Specification (CLS), such as C#. This approach is useful when a type library is unavailable.

To generate a primary interop assembly in source code

  1. Create an interop assembly in source code. For instructions, see Creating a Wrapper Manually. Note that you must include all COM types from the original type library when you create a primary interop assembly manually.

  2. At the assembly level, apply the following attributes:

    1. AssemblyKeyFileAttribute or AssemblyKeyNameAttribute, to specify the name of the file or container that contains the key pair to use when signing the assembly with a strong name.

    2. GuidAttribute, to specify the library identifier (LIBID) of the target type library.

    3. PrimaryInteropAssemblyAttribute, to identify the assembly as a primary interop assembly.

      NoteNote

      You can also delay sign an assembly when compiling. For more information, see Delay Signing an Assembly.

    The following code example applies the AssemblyKeyFileAttribute with a key file called CompanyA.snk and specifies that this assembly is a primary interop assembly supporting type library versions 4.2 and 5.2. As the example shows, you can wrap more than one version of a type library by applying additional assembly-level attributes.

    [assembly:AssemblyKeyFile(@"..\..\CompanyA.snk")]
    [assembly:Guid("97d25db0-0363-1cf-abc4-02608 c9e7553"]
    [assembly:PrimaryInteropAssembly(4, 2)]
    [assembly:PrimaryInteropAssembly(5, 2)]
    

See Also

Tasks

How to: Generate Primary Interop Assemblies Using Tlbimp.exe
How to: Wrap Multiple Versions of Type Libraries

Concepts

Generating Primary Interop Assemblies
Producing Primary Interop Assemblies