title: An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code, C#
body: <p>Im trying to work with databases and Entity-framework.</p>
  
  <p>Here Is my Database:</p>
  
  <p><a href="https://i.stack.imgur.com/8LfWi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8LfWi.png" alt="Database"></a></p>
  
  <p>I have the following file that creates an context:</p>
  
  <pre><code>namespace SportsStore.domain.Concrete
  {
      //Associate the model with the database
      //This class then automatically defines a property for each table in the database that I want to work with. 
      public class EFDbContext : DbContext { 
  
  
          public DbSet&lt;Product&gt; Products { get; set; }
  
          /*protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              modelBuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;();
          }*/
      }
  }
  </code></pre>
  
  <p>Here IS my file that Initialize the context-class:</p>
  
  <pre><code>namespace SportsStore.domain.Concrete
  {
      public class EFProductRepository : IProductRepository
      {
          private EFDbContext context = new EFDbContext();
  
          public IEnumerable&lt;Product&gt; Products
          {
              get { return context.Products.ToList(); } 
          }
      }
  }
  </code></pre>
  
  <p>When I run my application, I get the following error:</p>
  
  <blockquote>
    <p>An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code</p>
    
    <p>Additional information: Failed to set database initializer of type 'SportsStore.domain.Concrete, EFProductRepository' for DbContext type 'SportsStore.domain.Concrete, EFDbContext' specified in the application configuration. See inner exception for details.</p>
  </blockquote>
  
  <p>Here Is the details message of the inner exception:</p>
  
  <blockquote>
    <p>Can not load file or assembly EFDbContext or one of its dependencies. The system can not find the file EFDbContext</p>
  </blockquote>
  
  <p>Here Is my App.config:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;configuration&gt;
        &lt;configSections&gt;
          &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
          &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
        &lt;/configSections&gt;
        &lt;entityFramework&gt;
          &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"&gt;
            &lt;parameters&gt;
              &lt;parameter value="mssqllocaldb" /&gt;
            &lt;/parameters&gt;
          &lt;/defaultConnectionFactory&gt;
          &lt;providers&gt;
            &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
          &lt;/providers&gt;
        &lt;/entityFramework&gt;
        &lt;connectionStrings&gt;
          &lt;add name="EFDbContext" connectionString="data source=(LocalDb)\MSSQLLocalDB;initial catalog=SportsStore.domain.Concrete;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" /&gt;
        &lt;/connectionStrings&gt;
      &lt;/configuration&gt;
  </code></pre>
  
  <p>Here is my Web.Config:</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;!--
        For more information on how to configure your ASP.NET application, please visit
        http://go.microsoft.com/fwlink/?LinkId=301880
        --&gt;
      &lt;configuration&gt;
        &lt;configSections&gt;
          &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
        &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;&lt;/configSections&gt;
        &lt;appSettings&gt;
          &lt;add key="webpages:Version" value="3.0.0.0" /&gt;
          &lt;add key="webpages:Enabled" value="false" /&gt;
          &lt;add key="ClientValidationEnabled" value="true" /&gt;
          &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
        &lt;/appSettings&gt;
        &lt;system.web&gt;
          &lt;compilation debug="true" targetFramework="4.5.2" /&gt;
          &lt;httpRuntime targetFramework="4.5.2" /&gt;
        &lt;/system.web&gt;
        &lt;runtime&gt;
          &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
            &lt;dependentAssembly&gt;
              &lt;assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /&gt;
              &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
            &lt;/dependentAssembly&gt;
            &lt;dependentAssembly&gt;
              &lt;assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /&gt;
              &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
            &lt;/dependentAssembly&gt;
            &lt;dependentAssembly&gt;
              &lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /&gt;
              &lt;bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /&gt;
            &lt;/dependentAssembly&gt;
          &lt;/assemblyBinding&gt;
        &lt;/runtime&gt;
        &lt;system.codedom&gt;
          &lt;compilers&gt;
            &lt;compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" /&gt;
            &lt;compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&amp;quot;Web\&amp;quot; /optionInfer+" /&gt;
          &lt;/compilers&gt;
        &lt;/system.codedom&gt;
        &lt;entityFramework&gt;
  
          &lt;contexts&gt;
            &lt;context type="SportsStore.domain.Concrete, EFDbContext"&gt;
              &lt;databaseInitializer type="SportsStore.domain.Concrete, EFProductRepository" /&gt;
            &lt;/context&gt;
          &lt;/contexts&gt;
          &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"&gt;
            &lt;parameters&gt;
              &lt;parameter value="mssqllocaldb" /&gt;
            &lt;/parameters&gt;
          &lt;/defaultConnectionFactory&gt;
          &lt;providers&gt;
            &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
          &lt;/providers&gt;
        &lt;/entityFramework&gt;
      &lt;/configuration&gt;
  </code></pre>
  
  <p>How does it know which database to use?</p>
  
  <p>I'm new to Entity framework and databases in .NET. </p>