Reason:
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
- Open the EntrpriseLibrary.VSTS solution in Visual Studio.
- Ensure that you have GAX and Strong naming guidance package installed on your system.
- On Visual Studio select Tools->Guidance Package Manager
- Select 'Enable/ Disable Guidance Packages'
- Select the Strong Naming Guidance packages.
- 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.
- Right-click on the project/ solution folder and choose "Strong-name all projects in this solution or solution folder".
- 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.
- Press OK and the strong name guidance package will do the rest for you.
- 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,
PublicKey=002400000480000094000000060200000024000052534131000400000100010011
fc4f9f791dbe3a2ce058c143dcebb2580f5a081ace54c5980b2233da323df8a7a3000d318bfb
9faaa407d2d75d47158ff3eabf6e7e365561ecb5317a1903efd9f281135399e17ecdacd94a37
d14f2923451000abf6658c18f988b591bd45af44b057cb71f4825bed259268e187d0a75ce7f5
dee2c84d43ccd3e7d66d2509cf")]
- Now rebuild the entire solution.
- Use the sn-Vr option to skip verification for the assemblies.
2 comments:
Prajeesh this worked out great. I put a strong named library on my blog http://fixtheglitch.blogspot.com/ and made it available to your viewers.
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
Post a Comment