DbConfiguration instance used before 'EFConfiguration' type was discovered

c# entity-framework-6


In my MVC4 application I am having reference to my EF model assembly. Everything was working fine. All of a sudden I started getting below error message.

The default DbConfiguration instance was used by the Entity Framework before the 'EFConfiguration' type was discovered. An instance of 'EFConfiguration' must be set at application start before using any Entity Framework features or must be registered in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=260883 for more information.

I am using EF 6. Any idea what could be the reason? I double check with database and its updated and in sync with EF dll.

Update: I am getting this error when I am trying to instantiate Context object

mEntities context = new Entities();


7/1/2015 2:20:26 AM

Popular Answer

I just want to leave a solution for those having similar error message. As link from Vinicius Paiva, it clearly explains that if you have multiple dbcontex in different dlls, you should reference to your DbConfiguration file if you created one in your code. in my case I had azure functions project referencing on DAL project and only way to get azure functions project is to create partial class and code based DbConfiguration file.

So extending my edmx file DbContext with code below

namespace myApp.Data.Models
    partial class myDBEntities

        public myDBEntities(string connectionString) : base(connectionString)

      public  class myDBContextConfig : DbConfiguration
            public myDBContextConfig()
                SetDefaultConnectionFactory(new SqlConnectionFactory());

This DAL library was referencing on an MVC project where we had another edmx instance. So when I run on this project, it was throwing this exception. In order to fix this. you need to extend or add entityFramework node as below in your config file (web.config in this case)

<entityFramework codeConfigurationType="myApp.Data.Models.myDBContextConfig , myApp.Data">
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameter value="mssqllocaldb" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
1/9/2018 3:58:48 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow