mysql - EF DbContext 的 Linqpad 错误 : The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception

标签 mysql .net entity-framework linqpad

我很高兴在 Win7 机器上运行 LinqPad 4.47.02。我尝试添加 EF5/dbContext 连接。我选择我的程序集、程序集中的类以及此类程序集的配置文件。当我添加连接时,出现此错误:

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

我的 app.config 包含以下内容:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.data>
    <DbProviderFactories>
      <add name="MySQL Data Provider"
           invariant="MySql.Data.MySqlClient"
           description=".Net Framework Data Provider for MySQL"
           type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
    </DbProviderFactories>
  </system.data>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="FipavContextContainer" connectionString="metadata=res://*/FipavContext.csdl|res://*/FipavContext.ssdl|res://*/FipavContext.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=127.0.0.1;User Id=root;database=fipavmanagerdb&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>

我尝试按照建议评论配置文件中的标签 here但我遇到了同样的错误。

顺便说一句,连接有效,我有许多已保存的 linqpad 查询。当我尝试加载并运行其中一个时,linqpad 崩溃且没有任何附加信息。

我做错了什么?

谢谢你, F.

(奇怪)解决方案:

我尝试移动 <configSections>标记在 <system.data> 之前标签和错误飞走了

最佳答案

根据 msdn article对于 configSections 元素:

如果此元素位于配置文件中,则它必须是configuration元素的第一个子元素

我相信原因之一是该元素定义了处理程序来处理配置中的自定义部分,因此如果是第一个,则不需要多次读取解析配置来处理之前定义了自定义部分的情况该部分的处理程序已定义。

关于mysql - EF DbContext 的 Linqpad 错误 : The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19355763/

相关文章:

php - 如何避免在 html 表中打印重复值

.net - NUnit使用TestCase所需的清晰度

.net - 单元测试 Entity Framework

c# - 如何在一个类中创建一组方法/属性?

MySQL 计数/求和字段

mysql - Rails 3 序列化哈希值保存但不持久

.net - 如何从线程任务返回数据

.net - Visual Studio 2008 中的 ADO.Net 或 Entity Framework

java - 没有关闭就返回结果集?

.net - 当我们对子列表应用条件时,如何过滤父列表<>?