Cryptography in the Enterprise Library need some Help

Topics: Cryptography Application Block
May 8, 2008 at 1:12 PM
I am attempting to use Cryptography in the Enterprise Library for the first time I have reviewed the Cryptography Quick Start and believe my simple application is setup in a similar manner, However, I get an exception when I attempt to execute it. The exception is:
System.Configuration.ConfigurationErrorsException was unhandled
Message="An error occurred creating the configuration section handler for securityCryptographyConfiguration: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) (C:\\Documents and Settings\\jm29749\\My Documents\\Visual Studio 2005\\Projects\\CryptoTest\\CryptoTest\\bin\\Debug\\CryptoTest.vshost.exe.config line 5)"
Source="System.Configuration"
BareMessage="An error occurred creating the configuration section handler for securityCryptographyConfiguration: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"
Filename="C:\\Documents and Settings\\jm29749\\My Documents\\Visual Studio 2005\\Projects\\CryptoTest\\CryptoTest\\bin\\Debug\\CryptoTest.vshost.exe.config"
Line=5
StackTrace:
at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSourceImplementation.GetSection(String sectionName) in C:\EntLib3Src\App Blocks\Src\Common\Configuration\SystemConfigurationSourceImplementation.cs:line 62
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource.GetSection(String sectionName) in C:\EntLib3Src\App Blocks\Src\Common\Configuration\SystemConfigurationSource.cs:line 58
at Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.CryptographyConfigurationView.get_CryptographySettings() in C:\EntLib3Src\App Blocks\Src\Security\Cryptography\CryptographyConfigurationView.cs:line 68
at Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.CryptographyConfigurationView.GetSymetricCryptoProviderData(String symetricCryptoProviderName) in C:\EntLib3Src\App Blocks\Src\Security\Cryptography\CryptographyConfigurationView.cs:line 118
at Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.SymmetricCryptoProviderCustomFactory.GetConfiguration(String name, IConfigurationSource configurationSource) in C:\EntLib3Src\App Blocks\Src\Security\Cryptography\SymmetricCryptoProviderCustomFactory.cs:line 34
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedCustomFactory`2.Create(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) in C:\EntLib3Src\App Blocks\Src\Common\Configuration\ObjectBuilder\AssemblerBasedCustomFactory.cs:line 52
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedCustomFactory`2.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) in C:\EntLib3Src\App Blocks\Src\Common\Configuration\ObjectBuilder\AssemblerBasedCustomFactory.cs:line 82
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) in C:\EntLib3Src\App Blocks\Src\Common\Configuration\ObjectBuilder\Extensions\ConfiguredObjectStrategy.cs:line 62
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) in C:\EntLib3Src\App Blocks\Src\Common\Configuration\ObjectBuilder\Extensions\ConfigurationNameMappingStrategy.cs:line 55
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUpTTypeToBuild(IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUpT(IReadWriteLocator locator, String id, IConfigurationSource configurationSource) in C:\EntLib3Src\App Blocks\Src\Common\Configuration\ObjectBuilder\EnterpriseLibraryFactory.cs:line 176
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUpT(String id, IConfigurationSource configurationSource) in C:\EntLib3Src\App Blocks\Src\Common\Configuration\ObjectBuilder\EnterpriseLibraryFactory.cs:line 140
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.NameTypeFactoryBase`1.Create(String name) in C:\EntLib3Src\App Blocks\Src\Common\Configuration\ObjectBuilder\NameTypeFactoryBase.cs:line 64
at Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.Cryptographer.EncryptSymmetric(String symmetricInstance, Byte[] plaintext) in C:\EntLib3Src\App Blocks\Src\Security\Cryptography\Cryptographer.cs:line 151
at Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.Cryptographer.EncryptSymmetric(String symmetricInstance, String plaintext) in C:\EntLib3Src\App Blocks\Src\Security\Cryptography\Cryptographer.cs:line 166
at CryptoTest.Program.Main(String[] args) in C:\Documents and Settings\jm29749\My Documents\Visual Studio 2005\Projects\CryptoTest\CryptoTest\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

It is more than likely somthing I missed but, I have been looking at it for 2 days with no progress.
May 19, 2008 at 4:45 PM
Hi,

This looks like a mismatch between the version of EntLib's assemblies specified in the configuration file and the assembly references in your project. Most likely, you've included EntLib's source code projects in your solution, but the configuration tool is using the signed binaries. If this is the case and you're using the IDE configuration tool, you need to change the "configuration set" property in the solution to EntLib3Src; there's some information about using different assemblies in this EntLib doc page.

Fernando