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

Jan 13, 2012 at 11:33 AM
Edited Jan 14, 2012 at 9:10 AM

Hi all,

I use ODP.NET and version 4.1 of the Enterprise Library, vs 2008. And all is OK.

Now, migrate using ODP.NET Oracle.DataAccess 4.112.2.0 and version 5.0.414.0 of the Enterprise Library, vs 2010, .net 4.0.

Following a recent upgrade from version 4.1 to 5.0 of the Enterprise Library, once we get the following error:

Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type Database, key "ConnectionStrings.Oracle.xxx" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "ConnectionStrings.Oracle.xxx".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value.

References EntLib Forum: http://entlib.codeplex.com/discussions/215290

Now,  I have download source code of http://entlibcontrib.codeplex.com/

I open Data.OdpNet.QuickStarts.sln and change references to Enterprise Library 5.0.414.0. and change Target Framework to .NET 4.0

When I compiles, I get this error:

Error 1 Warning as Error: 'System.Security.Permissions.SecurityAction.RequestMinimum' is obsolete: '"Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information."' E:\Trabajo\Frk.Data\EntLibContrib5Src\Blocks\Data\Src\OdpNet\Properties\AssemblyInfo.cs 15 31 Data.OdpNet.2010


'System.Security.Permissions.SecurityAction.RequestMinimum' is obsolete, delete the attribute and all is compile right.

I use config for EntLibContrib like this http://entlibcontrib.codeplex.com/discussions/278682

And I get again this error:

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

Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type Database, key "ConnectionStrings.Oracle.xxx.EntLibContrib" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "ConnectionStrings.Oracle.xxx". Exception occurred while: while resolving. Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value....

I dont know what is the problem... any suggestions ?


Thanks.

Coordinator
Jan 16, 2012 at 1:51 PM

Hi kiquenet,

Regarding the Data.OdpNet.QuickStarts.sln project, change the "Treat warnings as errors" project property to "None". That should solve the "...RequestMinimum' is obsolete" compilation error.

About the config, I would recommend you to start with the config file from the QuickStart project. Make sure it works properly with the 5.0.414 references and .NET 4.0 (it currently references the 5.0.505 entlib assemblies and .NET 3.5). And then try to incorporate the working config to your main project.

Let me know how it goes.

Cheers,

Jeremi

 

 

Jan 17, 2012 at 2:27 AM
Edited Jan 17, 2012 at 2:28 AM

Hi guys,

I used that exact configuration a couple of days ago; it complained about a missing assembly "5.0.505.0" so I added a redirection rule like this:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Data" 
		publicKeyToken="31bf3856ad364e35" culture="neutral" />
      <bindingRedirect oldVersion="5.0.505.0" newVersion="5.0.414.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Common" 
		publicKeyToken="31bf3856ad364e35" culture="neutral" />
      <bindingRedirect oldVersion="5.0.505.0" newVersion="5.0.414.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>
I wonder if there is a better way to accomplish this :-)
Jan 17, 2012 at 2:33 AM

Of course I realize I was downgrading the version :-) I just wanted it to work with the binaries in my GAC

--Eulesv

Jan 17, 2012 at 10:48 AM

Thx.

I use now Data.OdpNet.QuickStarts.Console and 5.0.414.0 EntLib references.

EntLibContrib5Src\Quick Starts\Data.OdpNet\CS\Data.OdpNet.QuickStarts.Console

and I get this error:

A first chance exception of type 'Microsoft.Practices.ServiceLocation.ActivationException' occurred in Microsoft.Practices.ServiceLocation.dll

Error 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)".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,(none) 

---> System.InvalidOperationException: The type Database cannot be constructed. You must configure the container to supply this value.   at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor)   at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context)   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)   at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey)   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)   --- End of inner exception stack trace ---   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)   at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides)   at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key)   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)   --- End of inner exception stack trace ---   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]()   at Data.OdpNet.QuickStarts.Console.Program.Main(String[] args) in E:\Trabajo\Frk.Data\EntLibContrib5Src\Quick Starts\Data.OdpNet\CS\Data.OdpNet.QuickStarts.Console\Program.cs:line 15

 

any suggestions about it ?


The config file is:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=709072f126b4c05b" requirePermission="true"/>
    <section name="oracleConnectionSettings" type="EntLibContrib.Data.OdpNet.Configuration.OracleConnectionSettings, EntLibContrib.Data.OdpNet, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null" requirePermission="true"/>
  </configSections>

  <system.data>
    <DbProviderFactories>
      <add name="EntLibContrib.Data.OdpNet"
        invariant="EntLibContrib.Data.OdpNet"
        description="EntLibContrib Data OdpNet Provider"
        type="EntLibContrib.Data.OdpNet.OracleDatabase, EntLibContrib.Data.OdpNet, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null" />
    </DbProviderFactories>
  </system.data>

  <dataConfiguration defaultDatabase="Default Connection String">
    <providerMappings>
      <add databaseType="EntLibContrib.Data.OdpNet.OracleDatabase, EntLibContrib.Data.OdpNet, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null"
           name="EntLibContrib.Data.OdpNet"/>
    </providerMappings>
  </dataConfiguration>

  <oracleConnectionSettings>
    <add name="Default Connection String">
      <!--<packages>
        <add prefix="PKGNORTHWIND" name="NWND_"/>
        <add prefix="PKGENTLIB" name="RegionSelect"/>
      </packages>-->
    </add>
  </oracleConnectionSettings>

  <connectionStrings>
    <add name="Default Connection String"
         connectionString="DATA SOURCE=xxx;PASSWORD=xxxx;PERSIST SECURITY INFO=True;USER ID=xxx"
         providerName="EntLibContrib.Data.OdpNet"/>

   
  </connectionStrings>


  
    
    <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>


  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Data" publicKeyToken="709072f126b4c05b" culture="neutral" />
        <bindingRedirect oldVersion="5.0.505.0" newVersion="5.0.414.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Common" publicKeyToken="709072f126b4c05b" culture="neutral" />
        <bindingRedirect oldVersion="5.0.505.0" newVersion="5.0.414.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  
  
</configuration>

 

Jan 17, 2012 at 4:38 PM

Hi Kiquenet,

One comment regarding the assembly redirection, it was just to make it work against what I had installed, a better solution would be to get Enterprise Librariy binaries by using NuGet, that's why I was asking for a better approach. I think for basic tests it works well but dont use that rule for the "real stuff".

Now for your problem:

That sample should work, check if you have any missing reference, mine was refereing to Data.OdpNet2000.dll.

Jan 19, 2012 at 8:38 AM

Thanks a lot. Now, is all working using right configuration, like in  Data.OdpNet.QuickStarts.sln

Now, I  have any unit test that using DbProviderFactories.GetFactory(providerName);

providerName: EntLibContrib.Data.OdpNet

and I get this error: System.InvalidOperationException: The requested .Net Framework Data Provider's implementation does not have an Instance field of a System.Data.Common.DbProviderFactory derived type.

what about DbProviderFactories.GetFactory ? Any solution about it ?

The discussion is here: 

http://entlibcontrib.codeplex.com/discussions/286640

Thanks in advanced.