Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception

I have ASP.Net MVC site.

Technology Stack

  • ASP.Net 4.6
  • C#.Net
  • EF 6
  • MySQL -Database

While I am trying to generate the database using Nuget command:-

Enable-Migrations -force

I am getting the below exception

The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception.

Following things are already cross checked & tried by me:-

  • The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception on a Sub Website

  • The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception

  • Code First can't enable migrations

My App.Config:-

 <connectionStrings>
<add name="mydbContext" providerName="MySql.Data.MySqlClient" connectionString="Server=localhost;port=8080;database=mydb;uid=root;password=" />
</connectionStrings>



<entityFramework>
<defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory,   MySql.Data.Entity.EF6" />
<providers>
  <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
</providers>

like image 837
Kgn-web Avatar asked Nov 13 '16 10:11

Kgn-web


2 Answers

Have fixed it by making the configSections the first child of configuration in the config file.

<configuration> 

... ...

like image 76
Pankaj Jangid Avatar answered Oct 16 '22 09:10

Pankaj Jangid


In Entity Framework The type initializer error is most likely due to malformed Web.config files, like having two or more sections of connection string, or having problem in the connection string itself, such as invalid provider.

like image 32
Ashraf Sada Avatar answered Oct 16 '22 10:10

Ashraf Sada