Customize Enterprise application library

Topics: Data Access Application Block
May 19, 2014 at 5:14 PM
Edited May 19, 2014 at 5:15 PM

I am using enterprise library 6.0 in my project. I download the source code and built the project successfully. It created dlls in the bin directory. But when i copy those dlls to the bin directory of my project, i get error message. "Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common' .... version =, publickeytoke=null, or one of its dependencies. The located assembly's manifest definition does not match the assembly reference"

When i include the dlls from the binaries, this error does not come, but in the constructor of Database.cs file, i want to encrypt the connection string. So, i am compiling the code and getting the dlls from the bin. Is what i am doing is correct?. Please help me to do this.

Please note that, i have used my own library(dll) for encryption of the connection string. So i have added reference for this dll in the "Microsoft.Practices.EnterpriseLibrary.Data" project in the solution.

protected Database(string connectionString, DbProviderFactory dbProviderFactory)
this.connectionString = mylib.getconstring();

this is only line that i am modifying in the solution. The error is in GetConfigSecion function of "Microsoft.Practices.EnterpriseLibrary.Common". Please help.

Thanks in advance.
May 20, 2014 at 6:24 AM
Edited May 20, 2014 at 6:25 AM
Did you update the references for your project when you switched to a custom (unsigned) build? The referenced assembly information will be placed in your projects assembly manifest and if the version or PublicKeyToken do not match you will get the assembly manifest definition error.

You should build the custom version of Enterprise Library, add the custom assemblies as references to your project and ensure that the assemblies are in the correct (output) folder. If you are going with a custom build you will need to use all Enterprise Library assemblies from your custom build.

I'm curious if it is possible to obtain the decrypted connection string and programmatically set the Database objects with that connection string? That way you would not have to modify Enterprise Library source code. For example:
string connectionString = mylib.getconstring();
// Does not have to be a SqlDatabase
SqlDatabase db = new SqlDatabase(connectionString);

DatabaseFactory.SetDatabases(() => db, name => db);
Randy Levy
Enterprise Library support engineer
Support How-to
May 24, 2014 at 12:01 PM

Thank you so much.

After adding these in web.config, it worked

< .. "loggingConfiguration" type=",, culture=neutral, processArchitecture=MSIL" ..... />
< .. "dataConfiguration" type=",, culture=neutral, processArchitecture=MSIL" ..... />
< .. "exceptionConfiguration" type=",, culture=neutral, processArchitecture=MSIL" ..... />

Thank you so much for you help. I found these in assembly manifest file. However, there is no publickeytoken. Can you please tell how to add it, Or where can i find resources regarding the same.

I have not done any publickeytoken creation or assembly signing for any 3rd party tools before. So i do not have any idea about this. Your reply would be greatly helpful. Thanks
May 24, 2014 at 3:09 PM
Edited May 24, 2014 at 3:10 PM
You use the PublicKeyToken when an assembly is signed. If you are creating a custom build of Enterprise Library you are not required to sign the assemblies. See Creating and Using Strong-Named Assemblies for more information on strong names.

Randy Levy
Enterprise Library support engineer
Support How-to
Jun 10, 2014 at 6:58 PM
Edited Jun 10, 2014 at 7:02 PM
Thank you for the reply

But, i want to protect the dlls from tampering.
Also need to register into GAC.

My doubt is: Since, i use only 5 dlls from the enterprise library project, is it enough to strong name only these (by use of ildasm) or do i need to sign the entire project?

Please give me some suggestions.
Jun 11, 2014 at 1:38 AM
If you are only sign and deploy the assemblies that you are using you should be fine. Just make sure that you have sign and deploy all the dependent assemblies (e.g. Common). Also, you won't be able to use the out-of-the-box configuration tool with configuration for your new signed versions (if this is important to you).

Randy Levy
Enterprise Library support engineer
Support How-to
Jun 30, 2014 at 3:24 PM

Actually i signed the entire projects (including the test projects).

This worked without any issue.

Here is the link i used. It might be useful for someone.

Read this section in the link: "To create and sign an assembly with a strong name by using Visual Studio"

Thanks a lot.