Impact 2023 (Dynamic Constraints Edition) release is available for download, bringing with it a host of new features. Available here.

COM Assemblies

This article describes the necessity to create strong-named assemblies for the Impact COM type libraries.

Introduction

In order to develop flexible plugins which make use of the Impact COM libraries using Microsoft Visual Studio .NET (MVS .NET) the plugins developed must be strong-named assemblies so that they may be installed in the Global Assembly Cache (GAC). This is analogous to how the system registry is used for COM components. An assembly developed with MVS .NET that is to be strong-named can only reference assemblies that are themselves strong-named. Since any plugins developed will reference the Impact COM libraries these libraries must be strongly named. If a plugin is developed that is not strong-named and therefore cannot be installed in the GAC then the plugin must be installed in the same location as the Impact executable. The creation of strong-named assemblies overcomes this problem.

When a MVS .NET Impact plugin developer references the Impact libraries they do so by selecting the COM type library from the list of registered type libraries. MVS .NET then automatically generates an assembly from the type library which is not strong-named, usually a file called Interop.Impact.dll. Strong-named assemblies can be provided for MVS .NET developers which they can use to create their own strong-named assemblies containing plugins that can be used in Impact.

Every time Impact is built the strong-named assemblies provided for MVS .NET developers must be regenerated to incorporate any new interface properties or methods. This can be easily added as an automatic part of our build process.

Assembly Placement (msdn)

For most .NET Framework applications, you locate assemblies that make up an application in the application's directory, in a subdirectory of the application's directory, or in the global assembly cache (if the assembly is shared). You can override where the common language runtime looks for an assembly by using the element in a configuration file. If the assembly does not have a strong name, the location specified using the element is restricted to the application directory or a subdirectory. If the assembly has a strong name, you can specify any location on the computer or on a network.

Similar rules apply to locating assemblies when working with unmanaged code or COM interop applications: if the assembly will be shared by multiple applications, it should be installed into the global assembly cache. Assemblies used with unmanaged code must be exported as a type library and registered. Assemblies used by COM interop must be registered in the catalogue, although in some cases this registration occurs automatically.

About strong-named assemblies (msdn)

A strong name consists of the assembly's identity — its simple text name, version number and culture information (if provided) — plus a public key and a digital signature. It is generated from an assembly file using the corresponding private key. (The assembly file contains the assembly manifest, which contains the names and hashes of all the files that make up the assembly.)

Once an assembly is assigned a strong name all assemblies that reference that assembly must also have strong names so that the security of the strong-named assembly is not compromised.

Creating strong-named assemblies

The process of creating a strong-named assembly involves making use of some of the utility applications provided with MVS .NET. A strong-named assembly must be created for both Impact.tlb contained in the Impact executable and for ImpactCAD.tlb contained in basecad.dll.

Creating a key pair

The first step of creating a strong-name assembly is to generate a public and private cryptographic key pair (a .snk file) using the utility application sn.exe, which can be found in a sub folder of the MVS .NET installation folder.

The following command line will generate a unique key pair for the Impact type library.

sn.exe –k Impact.snk

The same must be done for the ImpactCAD type library.

sn.exe –k ImpactCAD.snk

Creating the assembly

The next step is to generate the assemblies incorporating the .snk files into the assemblies using the utility application tlbimp.exe that can also be found in a sub folder of the MVS .NET installation folder.

The .snk files created earlier should now be copied to the folder containing the application tlbimp.exe.

The following command line will import the type library from the Impact executable and the public and private cryptographic key pair from Impact.snk and compile this into a strong-named assembly, the file generated will be Impact.dll.

tlbimp d:\impact_12.0\impact.exe /keyfile:Impact.snk

Similarly, for the ImpactCAD type library which will generate ImpactCAD.dll.

tlbimp d:\impact_12.0\basecad.dll /keyfile:ImpactCAD.snk

Installing the assembly

Once the assemblies have been created they can be installed into the GAC simply by dragging them into the special explorer folder, Windows\Assembly. Assemblies can also be installed as part of the installation process using InstallShield or using the utility application regasm.exe.

As an optional task a MVS .NET developer can make the assemblies visible to MVS .NET by adding the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.0\AssemblyFolders\Impact\

A string value under this key should then be created that defines the folder where the Impact assemblies are located (the installation folder, probably).

Once the assemblies have been installed a plugin developer can reference the assemblies specifically instead of referencing the type libraries in the traditional way. Since these assemblies are strong-named the developer can also define their assembly as a strong-named assembly by creating their own public and private cryptographic key pair (.snk file) and signing their assembly with it.

The following code fragment placed in the AssemblyInfo.vb module shows how a VB .NET developer would generally define this.

[Visual Basic]

<Assembly: AssemblyKeyFileAttribute("key.snk")>

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.

You may like to read -