<{{Subtitle_Weight}} class="prominent-subhead {{Show_Subtitle}}"> {{Header_Subtitle}}

How to Strongly Name prebuilt assemblies

This article has been archived, and/or refers to legacy products, components or features. The content in this article is offered "as is" and will no longer be updated. Archived content is provided for reference purposes only. This content does not infer that the product, component or feature is supported, or that the product, component or feature will continue to function as described herein.

What do you do if you need to apply a strong name to an assembly that was provided, already compiled, to you and you don't have the source?

When adding an assembly to the Global Assembly Cache (GAC) and the assembly contains a reference to another assembly, the referenced assembly must also be strongly named.
Note: Only Strongly Named Assemblies can be added to the GAC.
A strong name constitutes the assembly's identity, which is:
  • Its simple text name
  • Version number
  • Culture information (if provided)
  • 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.)
Note: Once you give an assembly a strong name, all referenced assemblies must have strong names as well. This ensures that the security of the strongly named assembly is not compromised. Strong naming is applied to the assembly when it is created.
To illustrate, the K2mng.dll is not strongly named. Therefore, any assembly that references it cannot be added to the GAC.
To work around this do the following:
1) Produce the Microsoft intermediate language (MSIL) for the assembly using the ILDASM.EXE utility

i. Obtain the MSIL for the provided assembly
  From a VS.NET command prompt, enter the following: (assuming you have copied the K2mng.dll to C:\)
  c:\>ildasm k2mng.dll /out:k2mng.il
ii. Rename/move the original assembly
  Rename C:\K2mng.dll to K2mng.old or move the file to a different location.
iii. Create a new assembly from the MSIL output and your assembly keyfile
  Assuming you already have an assembly key pair file (if not, see below), do the following from a VS.NET command prompt:
  c:\>ilasm K2mng.il /dll /key=K2mng.snk

2) When step #1 is complete use an assembly key file to sign that MSIL into a new DLL using the ILASM.EXE utility

i. Create a strong name assembly key file
  From a VS.NET command prompt, use the SN.EXE utility to create a file containing the public key/private key pair:
  c:\>sn -k c:\K2mng.snk