a developer's notes – a semi-technical web development BLOG

March 12, 2013

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

I had a class library project that contains the Entity Framework .edmx file. In the same solution, I had a console application that consumed the class library project. But when I tried to run the console application to run a simple query on the DbContext object, got this error:

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

In the app.config:

<?xml version="1.0" encoding="utf-8"?>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <add name="AdventureWorksLTEntities" connectionString="metadata=res://*/AWModel.csdl|res://*/AWModel.ssdl|res://*/AWModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DNGUYEN-DESKTOP;initial catalog=AdventureWorksLT;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameter value="v11.0" />

Make sure the <startup> element is AFTER the <connectionStrings> element.



  1. delete the entityframework line in the app.config file and then click tools->Library Package Manger->Manage NuGet Packages and re-add the EntityFramework

    Comment by richard — May 28, 2015 @ 4:40 am | Reply

    • Omg, thank you so much! this worked for me, because I just upgraded to 5 with nuget….. THANK YOU!!

      Comment by Teto — August 12, 2016 @ 9:57 am | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: