Exception loading assembly for dataConfiguration section of app.config

Topics: Data Access Application Block, General discussion
Jul 13, 2007 at 3:24 PM
I'm just getting started migrating a large ELB 1.1/.NET 1.1/VS2003 app to ELB 3.1/.NET 2.0/VS2005, so I'm a newbie to ELB 3.1...

I finally got a first clean compile and then created my App.config using the VS-integrated EL config tool. But my first call to DatabaseFactory.CreateDatabase gets an exception:

System.Configuration.ConfigurationErrorsException An error occurred creating the configuration section handler for dataConfiguration: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Data, Version=, 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:\Projects\USM VERS 1.6.1 - ELB 3.1 - NET 2.0 - VS2005 - 06 Jul 07\PrimaryUI\bin\Debug\UltraSM.vshost.exe.config line 6)

Line 6 of my App.config file has:

<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

And so I SUSPECT that the exception may be caused by the config file referencing a signed assembly, and the ELB blocks that I've built - and which are present in ~\bin\debug at run time - aren't signed (although my experience with signed assemblies is almost nil).

But why does the config file generated by the config tool specify a PublicKeyToken value? The config for the Data block QuickStart has PublicKeyToken-=null, and it runs OK. I tried manually editing my app.config to specify PublicKeyToken=null (for only the dataConfiguration section), but then I get a different exception: "The value can not be null or an empty string."

Or am I totally going down the wrong path?



Jul 13, 2007 at 4:17 PM
Hi DT,

You need to specify a different "configuration set" for your solution. The details are explained in this post from Tom http://blogs.msdn.com/tomholl/archive/2007/04/19/avoiding-configuration-pitfalls-with-incompatible-copies-of-enterprise-library.aspx.

Hope this helps,
Jul 16, 2007 at 8:19 PM

Thanks! Tom's article explained a LOT, and after I'm making the changes to separate the MS-provided (signed) assemblies from the ones I built, and to use the correct config tools, I've made some progress... no more "could not load assembly.." errors, at least!

However, I'm still getting an exception from CreateDatabase. I suspect my app.config file still isn't being constructed properly by the VS-integrated config tool... my file doesn't have a <dataConfiguration> element, for example, even though there's a reference to it in the <configSections>::

<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=, Culture=neutral, PublicKeyToken=null" />

Jul 16, 2007 at 9:18 PM
Found the problem! If you don't specify a default database, the generated .config file is invalid.

Seems like the config tools have a problem...

Jul 16, 2007 at 9:35 PM

This doesn't seem to be a problem with the tools but with the configuration being inadequate for its intended usage.

Serialization of configuration information will only write values that are different from defaults. The database configuration section has a single value, the default database, so if that attribute is empty the section itself will not be written to a file but it will be accessible at runtime; it will just happen to have default values for its attributes.

You did not provide information about the exception you got from CreateDatabase, but it's likely the you were calling the override that creates an instance of the default database which requires the default database to be set.