Activation error occured while trying to get instance of type Database, key ""

Topics: Data Access Application Block
Sep 5, 2012 at 1:54 PM

Hi,

I am using Oracle.DataAcces 2.102.2.20 for Oracle 8I and Visual Studio 2010. When I try to start a project, I got following error: “Activation error occured while trying to get instance of type Database, key “”".

The Exception is Microsoft.Practices.ServiceLocation.ActivationException on
database = EnterpriseLibraryContainer.Current.GetInstance<Database>();

The message for the InnerException is:

Resolution of the dependency failed, type = “Microsoft.Practices.EnterpriseLibrary.Data.Database”, name = “DefaultConnectionString”.
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,DefaultConnectionString

My App.config file is:

<?xml version="1.0" ?>
<configuration>

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

<dataConfiguration defaultDatabase="DefaultConnectionString">
<providerMappings>
<add databaseType="EntLibContrib.Data.OdpNet.OracleDatabase, EntLibContrib.Data.OdpNet, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null" name="Oracle.DataAccess.Client"/>
</providerMappings>
</dataConfiguration>

<connectionStrings>
<add name="DefaultConnectionString" connectionString="Data Source=toy;User ID=hr;Password=hr;Persist Security Info=True;" providerName="Oracle.DataAccess.Client"/> </connectionStrings>

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

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89B483F429C47342" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.112.3.0" newVersion="4.112.3.0"/> </dependentAssembly>
</assemblyBinding>
</runtime>

</configuration>

 

I can workaround the problem by changing the target framework from .Net Framework 4 to .Net Framework 3.5 and line in app.config to:
<add databaseType="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase, Microsoft.Practices.EnterpriseLibrary.Data" name="Oracle.DataAccess.Client"/>

But, I still want to use .Net Framework 4 as Target framework.

How i can solve the problem?

Regards, Dmitry

 

Sep 6, 2012 at 3:48 AM
Edited Sep 6, 2012 at 3:49 AM

My guess is that the machine.config for .NET 4 (located in C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config or C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config depending on whether the 64 bit version is being used) does not contain the the DbProviderFactories.

It should look something like:

<system.data>
  <DbProviderFactories>
    <add name="Oracle Data Provider for .NET" invariant="Oracle.DataAccess.Client"
description="Oracle Data Provider for .NET" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=2.102.2.20, Culture=neutral, PublicKeyToken=89b483f429c47342" />
  </DbProviderFactories>
</system.data>

Or you can check for differences between the .NET 3.5 (which does work) machine.config (usually located at C:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG or C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG).

You can also add the above config to your app.config.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Sep 6, 2012 at 1:59 PM
Thank you very match for solving the issue.