title: An unhandled exception of type 'System.TypeInitializationException' occurred in EntityFramework.dll
body: <p>I was trying to learn <a href="http://en.wikipedia.org/wiki/ADO.NET_Entity_Framework" rel="noreferrer">Entity Framework</a> and <a href="http://en.wikipedia.org/wiki/SQLite" rel="noreferrer">SQLite</a> using <a href="http://brice-lambson.blogspot.no/2012/10/entity-framework-on-sqlite.html" rel="noreferrer">this tutorial</a>. However, I get an error.</p>
  
  <p>The error thrown is:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.TypeInitializationException' occurred in EntityFramework.dll</p>
    
    <p>Additional information: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.</p>
  </blockquote>
  
  <p>Here is the full error trace:</p>
  
  <pre><code>System.TypeInitializationException: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. ---&gt; System.Configuration.Configuration
  ErrorsException: Configuration system failed to initialize ---&gt; System.Configuration.ConfigurationErrorsException: Only one &lt;configSections&gt; element allowed per config file and if present must be the first child of the root &lt;configuration&gt;
  element. (C:\Users\Ankur\Documents\Visual Studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.vshost.exe.config line 11)
     at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
     at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
     at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
     at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
     --- End of inner exception stack trace ---
     at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
     at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
     at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
     at System.Configuration.ConfigurationManager.get_ConnectionStrings()
     at System.Data.Entity.Internal.AppConfig..ctor()
     at System.Data.Entity.Internal.AppConfig..cctor()
     --- End of inner exception stack trace ---
     at System.Data.Entity.Internal.AppConfig.get_DefaultInstance()
     at System.Data.Entity.Internal.LazyInternalConnection..ctor(String nameOrConnectionString)
     at System.Data.Entity.DbContext..ctor()
     at ConsoleApplication1.ChinookContext..ctor()
     at ConsoleApplication1.Program.Main(String[] args) in c:\Users\Ankur\Documents\Visual Studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs
  :line 16
  </code></pre>
  
  <p>Here is the C# code:</p>
  
  <pre><code>namespace ConsoleApplication1
  {
      class Program
      {
          static void Main(string[] args)
          {
              using (var context = new ChinookContext()) //error comes on this line
              {
              }
          }
      }
  
      class ChinookContext : DbContext
      {
      }
  }
  </code></pre>
  
  <p>Here is file <em>App.config</em>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;system.data&gt;
      &lt;DbProviderFactories&gt;
        &lt;add name="SQLite Data Provider" invariant="System.Data.SQLite" description="Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /&gt;
      &lt;/DbProviderFactories&gt;
    &lt;/system.data&gt;
    &lt;connectionStrings&gt;
      &lt;add name="ChinookContext" connectionString="Data Source=|DataDirectory|Chinook_Sqlite_AutoIncrementPKs.sqlite" providerName="System.Data.SQLite" /&gt;
    &lt;/connectionStrings&gt;
    &lt;configSections&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
    &lt;/configSections&gt;
    &lt;startup&gt;
      &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
    &lt;/startup&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"&gt;
        &lt;parameters&gt;
          &lt;parameter value="v11.0" /&gt;
        &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
    &lt;/entityFramework&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Here is file <em>packages.config</em>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;packages&gt;
    &lt;package id="EntityFramework" version="5.0.0" targetFramework="net45" /&gt;
    &lt;package id="System.Data.SQLite.x86" version="1.0.86.0" targetFramework="net45" /&gt;
  &lt;/packages&gt;
  </code></pre>