Friday, August 03, 2007

Enterprise Library Assemblies are Strongly Named

Alright how does that affect you? Well... in a very simple way, look at these two configuration files that are taken from Enterprise Library 2.0.0.0 and 3.1.0.0

2.0.0.0:

<text>
<configuration>
<configsections>
<section name="securityCryptographyConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.Configuration.CryptographySettings, Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null">
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null">
</section>
<securitycryptographyconfiguration defaulthashinstance="PasswordHasher">
<hashproviders>
<add algorithmtype="System.Security.Cryptography.SHA1Managed, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" saltenabled="true" type="Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.HashAlgorithmProvider, Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="PasswordHasher">
</add>
</hashproviders>
<enterpriselibrary.configurationsource selectedsource="System Configuration Source">
<sources>
<add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null">
<add name="userStore" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" filepath="..\..\UserStore.config">
</add>
</add>
</sources>
</enterpriselibrary.configurationsource></securitycryptographyconfiguration></section></configsections></configuration>

3.1.0.0:


<configuration>
<configsections>
<section name="securityCryptographyConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.Configuration.CryptographySettings, Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
</section>
<securitycryptographyconfiguration defaulthashinstance="PasswordHasher">
<hashproviders>
<add algorithmtype="System.Security.Cryptography.SHA1Managed, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" saltenabled="true" type="Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.HashAlgorithmProvider, Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="PasswordHasher">
</add>
</hashproviders>
<enterpriselibrary.configurationsource selectedsource="System Configuration Source">
<sources>
<add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<add name="userStore" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" filepath="..\..\UserStore.config">
</add>
</add>
</sources>
</enterpriselibrary.configurationsource></securitycryptographyconfiguration></section></configsections></configuration>

Do you see the difference? Yes, the config files are referring to different version of the Enterprise Library and also the 3.1.1.0 version has a public key token.

The reason for that is because the first config file is taken from the Enterprise Library hands on lab and has no public token, because it's supposed to easily work on any machine; however it is still looking for version 2.0.0.0. So whenever you try to build the solution from the hands on labs, you would get some weird exception and usually when you catch the inner exception, you would be able to see the actual problem. In my case, Visual Studio was unable to load Microsoft.Practices.EnterpriseLibrary.Common, but for enterprise library 2.0.0.0. I don't have that animal installed on my machine, so I was getting the error.

It won't even help if you try to open the App.config file with the Enterprise Library Configuration Tool, as it will try to open it with the old version of the ent. Lib assemblies bleh...
The only solution is to get the token and version from another config file and manually replace each entry.

Voila problem solved...

No comments: