Microsoft KB Archive/304295

= How to create a Primary Interop Assembly (PIA) =

Article ID: 304295

Article Last Modified on 5/8/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0

-



This article was previously published under Q304295



IN THIS TASK

 * SUMMARY
 * Requirements
 * Create a Primary Interop Assembly (PIA)
 * REFERENCES



SUMMARY
A Primary Interop Assembly (PIA) contains the official description of types as defined by the types publisher. A PIA is an assembly that contains a signed set of wrapper classes that enables you to call unmanaged code from managed code.

A PIA is a unique vendor-supplied assembly that contains the type definitions of types that are implemented by using the Component Object Model (COM). In a PIA, the type definitions are contained as metadata. The COM type library publisher must sign only one PIA with a strong name. A single PIA can wrap more than one version of the same type library.

A COM type library that is imported as an assembly and that is signed by someone other than the original type library publisher cannot be a PIA. Only the type library publisher can create a PIA that becomes the unit of official type definitions for interoperating with the underlying COM types.

back to the top

Requirements
This article assumes that you are familiar with the following topics:
 * Microsoft .NET Framework

The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
 * Microsoft .NET Framework 1.1 or Microsoft .NET Framework 1.0

back to the top

Create a Primary Interop Assembly (PIA)
To create a PIA, follow these steps:  Create a COM object.  If you already have a key file, skip this step. Go to step 3.

If you do not already have a key file, use the sn.exe tool to create a key file. To do this, run the following command at a Visual Studio .NET command prompt: sn -k mykey.snk   Generate an assembly from the COM type library. To do this, run the following command at the Visual Studio .NET command prompt: TLBIMP MyCOMServer.dll /out:MyWrappers.dll /keyfile:mykey.snk /primary   Register the generated assembly. To do this, run the following command at the Visual Studio .NET command prompt: regasm MyWrappers.dll This command adds the following entries in your registry that designate the assembly as a PIA:

 

 

 

The Assembly value is mandatory. The Assembly value must specify the full string form of the assembly name, including the version, the culture, and the publisher key.

The CodeBase value and the WebService value are optional. The CodeBase value specifies the URLs from where the assembly can be downloaded. The WebService value provides a URL that the .NET Framework can query to determine the code base of the assembly.   Add the PIA to the Global Assembly Cache (GAC). To do this, run the following command at the Visual Studio .NET command prompt: gacutil -i MyWrappers.dll 

back to the top

