Monday, May 5, 2008

Strong Naming The Enterprise Library

Enterprise Library comes with a collection of application blocks and guidance documents that together provide functionality common to enterprise applications. But most of the users of the application blocks would have faced the problems with the application blocks assembly when you try to strong name your assemblies which have references to the Enterprise Library


Enterprise Library assemblies are not strong named

You need to sign the enterprise library assemblies if you want to install it into the GAC/ to add a reference to a strong named assembly.

In this article I will explain how to delay sign your Enterprise Library assemblies and use it with a strong named assembly.

Tom Hollander has mentioned the process of strong naming the Enterprise library assemblies in his post on Enterprise Library Update and Strong Naming Guidance Package

In this article I will explain the entire process of strong naming the enterprise library assemblies with details that may help the users using Enterprise Library in their applications.

Using the Strong Naming Guidance Package

  1. Open the EntrpriseLibrary.VSTS solution in Visual Studio.
  2. Ensure that you have GAX and Strong naming guidance package installed on your system.
  3. On Visual Studio select Tools->Guidance Package Manager
  4. Select 'Enable/ Disable Guidance Packages'
  5. Select the Strong Naming Guidance packages.
  6. Right-click on a project/ solution folder and choose "Create a new strong-name key pair file". This will create a string name key file for signing the assemblies.
  7. Right-click on the project/ solution folder and choose "Strong-name all projects in this solution or solution folder".
  8. Use the key file created in step 6 for strong naming the assemblies. Also select the "Update InternalsVisibleTo" checkbox to tell the recipe to search for this attribute and add the public key.
  9. Press OK and the strong name guidance package will do the rest for you.
If you don't have the Strong Naming Guidance Package installed in your system you can manually configure the assemblies by following the steps given below.

  • Open the visual studio command prompt and create a strong name key file.
  • Extract the public key file from the strong name file.
  • Use sn-tp to see the hex decimal form of the public key from the public key file, and copy the hex key to a notepad for later use.
  • Now open the enterprise library source code and then delay sign the projects using the public key file. For that right click the project and select Add Existing Item

  • Open the folder where the public key file is stored. Select the public key file and click on Add as link in the dialog box. This will add the reference to the key file.
  • Right click the project and select properties.
  • On the signing tab check the Sign the assembly check box and select the public key file name displayed in the drop down list.
  • Check the delay sign only check box also.

  • Now search for “InternalsVisibleTo in the entire solution and add the PublicKey= option to the attribute. (Use the hex value that is copied in step 3 for this) Eg: [assembly: InternalsVisibleTo("Microsoft.Practices.EnterpriseLibrary.Caching.Tests,


  • Now rebuild the entire solution.
  • Use the sn-Vr option to skip verification for the assemblies.


LowerLevelInmate said...

Prajeesh this worked out great. I put a strong named library on my blog and made it available to your viewers.

Todd said...

Thanks for the great post. Just an FYI that I had to do the following to get the hex code:
sn -k mykey.snk
sn -p mykey.snk mykey.bin
sn -tp mykey.bin