'System.Data.Entity.Migrations.DbMigrationsConfiguration`1'的类型初始值设定项引发了异常 [英] The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception

查看:466
本文介绍了'System.Data.Entity.Migrations.DbMigrationsConfiguration`1'的类型初始值设定项引发了异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ASP.Net MVC个站点.

技术堆栈

  • ASP.Net 4.6
  • C#.Net
  • EF 6
  • MySQL-数据库

当我尝试使用Nuget命令生成数据库时:-

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

Enable-Migrations -force

我收到以下异常

"System.Data.Entity.Migrations.DbMigrationsConfiguration`1"的类型初始值设定项引发了异常.

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

以下内容已经经过交叉检查和检查;我尝试过:-

类型"System.Data.Entity.Internal.AppConfig"的初始化程序引发了异常

代码优先"无法启用迁移

我的App.Config:-

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>

推荐答案

在Entity Framework中,The type initializer错误最有可能是由于Web.config文件格式错误,例如具有两个或多个连接字符串部分,或者在连接字符串本身,例如无效的提供程序.

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.

这篇关于'System.Data.Entity.Migrations.DbMigrationsConfiguration`1'的类型初始值设定项引发了异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆