The type Database cannot be constructed. You must configure the container to supply this value.

Feb 18, 2013 at 8:11 PM
Edited Feb 18, 2013 at 8:12 PM
Getting "Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value." error when upgrading from EntLib 4.1 to 5.0.

config;
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<dataConfiguration defaultDatabase="Sample"/>
<connectionStrings>
<add name="Sample" connectionString="Database=Sample;Server=DB-Sample;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
</connectionStrings>

code;
        Database objDB = DatabaseFactory.CreateDatabase(this.__DatabaseKey);
Feb 18, 2013 at 8:47 PM
I see there is an Issue Tracker issue (http://entlib.codeplex.com/workitem/26903) for this related to EntLib 5.0 files in the GAC. But, half of the data in the issue seems to be missing. Is there an update to the config file I can make to get this working?
Feb 18, 2013 at 9:56 PM
It seems like the recent CodePlex upgrade has resulted in some older comments not being rendered correctly.

The missing part of that comment was to add the following to the appropriate configuration file (app.config or web.config):
<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <qualifyAssembly partialName="Microsoft.Practices.EnterpriseLibrary.Data" fullName="Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </assemblyBinding>
</runtime>
~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Feb 19, 2013 at 5:31 PM
Edited Feb 19, 2013 at 5:32 PM
Adding this to my config file resolved my issue.