开发者

System.InvalidOperationException: The type Database cannot be constructed

开发者 https://www.devze.com 2023-04-10 01:09 出处:网络
I have been looking into refactoring some old code into a new WCF service, based on net 4.0 and have into a little difficulty with what should be a simple exercise!

I have been looking into refactoring some old code into a new WCF service, based on net 4.0 and have into a little difficulty with what should be a simple exercise!

The scenario;

WCF Service hosted over HTTP, implementing our ServiceContract, which connects to a local Sql Server.

When attempting to run a simple NUnit test against the Service Call, I get the following error;

* HelpManager.Tests.GetPage.GetPageById Fault Exception: System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Activation error occured while trying to get instance of type Database, key "HelpManagement" (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type Database, key "HelpManagement" ----> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "HelpManagement". Exception occurred while: while resolving. Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value. ----------------------------------------------- At the time of the exception, the container was:

Resolving Microsoft.Practices.EnterpriseLibrary.Data.Database,HelpManagement ----> System.InvalidOperationException: The type Database cannot be 开发者_C百科constructed. You must configure the container to supply this value.

at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimiti...).

Our (pretty standard) WCF web.config for this, looks like;

<configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true"/>
</configSections>

<dataConfiguration defaultDatabase="HelpManagement"/>

<connectionStrings>
    <add name="HelpManagement" connectionString="server=(local);database=ieq;uid=;pwd=" providerName="System.Data.SqlClient"/>
</connectionStrings>

and an example of the code used to call it;

private const string DB_HelpManagement = "HelpManagement";
var db = DatabaseFactory.CreateDatabase(DB_HelpManagement);

Google et al have been no fun. I have checked versions etc and they all appear to be referencing the same 5.0.14 from GAC, so unsure as to what the problem is.

Thanks in advance


I wonder about Microsoft.Practices.ObjectBuilder.dll and Microsoft.Practices.EnterpriseLibrary.Common -- are they referenced in the WCF project?


It sounds like it might be your configuration. Did you specify the dataConfiguration defaultDatabase value in your config file (e.g. web.config)?

0

精彩评论

暂无评论...
验证码 换一张
取 消