3

Have a class library and a WPF application and am trying to contain all the Entity Framework items within the class library and use an interface to get the info out. Everything is setup but I get this message each time I try it out:

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

When I looked at the Inner Exceptions it appeared it couldn't find version 5.0.0.0 of EntityFramework and when I checked the Reference for it, it was 4.4.0.0. Tried uninstalling and reinstalling EntityFramework via NuGet but having no luck. Any ideas on what to try next?

App Config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- 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=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>
5
  • Can you post your web.config? Commented Sep 20, 2012 at 22:33
  • No it's not a web app, it's in a class library. Commented Sep 20, 2012 at 22:35
  • So....maybe your app.config then...? Commented Sep 20, 2012 at 22:35
  • Hmm, that looks correct. Do you also have EF installed on your computer, in addition to pulling it in from NuGet? Maybe that could be causing an issue. Commented Sep 20, 2012 at 22:42
  • I've used it in other projects without a problem on this computer, I have never manually installed it only used NuGet Commented Sep 20, 2012 at 22:43

3 Answers 3

4

I think this is a problem with your app.Config prehaps you dont have the following:

  <configSections>
    <!-- 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=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>

This needs to be in the config file for your application entry point (whatever executable/webapp is running/using your class library)

A key detail to note is that EF4.4 is released inside the EF5 package and is used for non-.NET 4.5 applications (ie if you have .net 4.5 your reference will be 5.0 otherwise with .net 4 it will be 4.4)

Sign up to request clarification or add additional context in comments.

3 Comments

should I change the .net version to 4.5 maybe?
its completely up to you, EF will work with either (assuming you have the above config for .net 4 or the alternative for .net 4.5) .net4.5 has lots of other cool stuff and i would highly recommend having it installed (for DB performance reasons) but as to weather you use it for your app its very much your decision
Just to make it clearer, if you upgrading your projects EntityFramework reference from .net40 to .net45 and you're getting the OP's error. You need to change "Version=4.4.0.0" to "Version=5.0.0.0" in the web.config of entry point website.
2

Uninstalled EntityFramework

Updated Class Library to .Net Version 4.5

Reinstalled EntityFramework

Now all working.

1 Comment

If this fails for some, try cleaning the project and rebuilding.
1

I have tried changing the version of EF in the webconfig to the current installed version of the EF on the project and everything works smoothly.

1 Comment

Thanks. Sure enough web.config <section name="entityFramework"...> had version "5.0.0.0" even though my DLL was "4.4.0.0".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.