N/Direct - The .NET Interoperability Resource Center 

FAQ

 

 

 

Most Valuable Professional

How do I give an interop assembly a strong name?
Written: 6/19/2002 Updated: 3/25/2003

First, if it's a COM component produced by a third party, check with the vendor if they have a Primary Interop Assembly (PIA) available. PIAs have a strong name and should have been tested to ensure that they work correctly. If it's your own component, or if no PIA is available, you can create an interop assembly yourself and give it a strong name.

If you're working with a C# project inside the Visual Studio .NET IDE, open the project properties dialog and navigate to Common Properties, General. There you'll find two options, Wrapper Assembly Key File and Wrapper Assembly Key Name, where you can enter the path to a key pair file or the name of a key container. From there on, the interop assembly for any COM component you reference will be given a strong name. Existing references will not be changed, so you might have to delete the reference and add it again.

No such option is available in VB.NET and many other languages. Instead, you have to use the command line tool TlbImp.exe that ships with the .NET Framework SDK. TlbImp is a more flexible tool for creating interop assemblies, and its two switches /keyfile and /keycontainer can be used to give the assembly a strong name. Once created, you can reference the interop assembly from the .NET tab of Visual Studio's Add Reference dialog box.

Note that an interop assembly created with a reference in VS.NET not always will be equivalent to one created with TlbImp, since they use different default settings. C# users might want to use TlbImp as well if the settings VS.NET uses aren't appropriate.

See also
PRB: "Assembly Generation Failed" Error Message When You Try to Build a Managed DLL Without a Strong Name (313666)
Primary Interop Assemblies (PIAs)