Enterprise Library Migration - You must configure the container to supply this value

I do not know who else will ask for help.

Here at my company, we are moving the system. From 2.0 to 3.5 no.

We use the corporate library 3.1 and we move on to 5.0

I used the tool for the configuration file

The compilation was fine, but when I started, I received this message:

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

Dependency resolution failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "MrvFramework". An exception occurred when: at resolution.

Exception: InvalidOperationException. A type database cannot be constructed. You must configure the container to deliver this value.

At the time of the exception, the container was: Permission Microsoft.Practices.EnterpriseLibrary.Data.Database

I spent a lot of time online:

I did these tests:

  • All DLL required by the corporate library is specified in the project
  • var database = DatabaseFactory.CreateDatabase(MrvFramework)
  • var database = EnterpriseLibraryContainer.Current.GetInstance<Database>(MrvFramework)
  • var database = new SqlDatabase(MrvFramework)

This is my app.config (fragment code)

 <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" /> <dataConfiguration defaultDatabase="MRVFramework"/> <connectionStrings> <add name="MRVFramework" connectionString="Data Source=H:\MRV\Projetos\MRV Framework\Branch\Update SqlServerCe\MRV.Framework.Seguranca.Console\MRVFramework.sdf;Persist Security Info=True" providerName="System.Data.SqlClient"/> </connectionStrings> 

This is my machine.config file

 <DbProviderFactories> <add name="Odbc Data Provider" invariant="System.Data.Odbc" description=".Net Framework Data Provider for Odbc" type="System.Data.Odbc.OdbcFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <add name="OleDb Data Provider" invariant="System.Data.OleDb" description=".Net Framework Data Provider for OleDb" type="System.Data.OleDb.OleDbFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <add name="OracleClient Data Provider" invariant="System.Data.OracleClient" description=".Net Framework Data Provider for Oracle" type="System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <add name="SqlClient Data Provider" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" /> </DbProviderFactories> 
+4
source share
2 answers

Add this code to your 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> 
+1
source

I was getting the same exception by executing the code below;

Database db = DatabaseFactory.CreateDatabase();

The exception was fixed when I updated the code to

 Database db = DatabaseFactory.CreateDatabase("Connection String"); // config file string 
0
source

Source: https://habr.com/ru/post/1436887/


All Articles