Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft