Obsolete Entity Framework Configuration Section

Problem

When the code is initializing a DbContext, the following error occurs:

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

Solution

Make sure the App.Config has the correct entity framework

    <section name=”entityFramework” type=”System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ requirePermission=”false” />   

In fact, you may not even need this configuration section at all.

Cause

In my case, I upgraded the project to use Entity Framework 5.0 but I did not change the App.Config.  So I had the following old entity framework setting in it:

<section name=”entityFramework” type=”System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″/>

Advertisements

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