Microsoft Knowledge Base Email Alertz

KBAlertz.com: (304295) - 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.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 304295 - Last Review: May 8, 2007 - Revision: 1.3

How to create a Primary Interop Assembly (PIA)

This article was previously published under Q304295

On This Page

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.

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

Create a Primary Interop Assembly (PIA)

To create a PIA, follow these steps:
  1. Create a COM object.
  2. 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
  3. 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
  4. 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:
    HKEY_CLASSES_ROOT\TypeLib\<typelib_guid>\version\lcid\PrimaryInteropAssembly\Assembly

    HKEY_CLASSES_ROOT\TypeLib\<typelib_guid>\version\lcid\PrimaryInteropAssembly\CodeBase

    HKEY_CLASSES_ROOT\TypeLib\<typelib_guid>\version\lcid\PrimaryInteropAssembly\WebService

    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.
  5. 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

REFERENCES

For more information about PIAs, visit the following Microsoft Web site:
http://msdn2.microsoft.com/en-us/library/aa302338.aspx (http://msdn2.microsoft.com/en-us/library/aa302338.aspx)

APPLIES TO
  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
Keywords: 
kbinterop kbcominterop kbhowtomaster KB304295
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please