简体   繁体   中英

Linqpad Error with EF DbContext: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception

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

As per msdn article for configSections element:

If this element is in a configuration file, it must be the first child element of the configuration element

I believe that one of the reasons is that this element defines handlers to handle custom sections in the config so if it is first you don't need to read parse config multiple time to handle a case where a custom section is defined before the handler for this section is defined.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM