The type Database does not have an accessible constructor.

Topics: Data Access Application Block, General discussion
Aug 18, 2012 at 8:40 PM

This is driving me crazy:

I have integration tests where I use Data Access Application Block (latest version as of today 5.0.505.0). And I code against it as always:

Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>();

But here it throws exception with this info:

Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type Database, key "" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "(none)".

Then in output:

Resolving Microsoft.Practices.EnterpriseLibrary.Data.Database,(none)
  ---> System.InvalidOperationException: The type Database does not have an accessible constructor.

What is this??? 

 

Aug 18, 2012 at 9:06 PM

Got it: when you get EntLib from nuget it doesn't add required sections to the web.config (app.config in my case). So you have to do it manually before using Data app block.