0

I happily run LinqPad 4.47.02 on a Win7 machine. I tried to add a EF5/dbContext connection. I choose my assembly, the class within the assembly and such assembly's config file. When I add the connection, i get this error:

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

My app.config contains this:

<?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>

I tried to comment the tag in configfile as suggested here but i get the same error.

As a side note, the connection worked and I have many saved linqpad queries. When I try to load and run one of them, linqpad crashes with no additional info.

What am I doing wrong?

Thank you, F.

(weird) SOLUTION:

I tried moving the <configSections> tag just before <system.data> tag and the error flied away

4

1 回答 1

2

根据configSections 元素的msdn 文章

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

我相信其中一个原因是这个元素定义了处理程序来处理配置中的自定义部分,所以如果它是第一次,你不需要多次读取 parse config 来处理在处理程序之前定义自定义部分的情况本节已定义。

于 2013-10-14T16:29:15.330 回答