25

I get an Unrecognized element 'providers' exception at runtime when I use Entity Framework 5.0.0 with .NET 4.0. Actually with .NET 4.0 it's the version 4.4.0 of Entity Framework that is loaded when I do an install-package with NuGet. When I check the properties of the file from explorer I can see this:

enter image description here

Here is my config file

 <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
  <connectionStrings>
    <add name="xxx" connectionString="metadata=res://*/StreetMusicModel.csdl|res://*/StreetMusicModel.ssdl|res://*/StreetMusicModel.msl;         provider=MySql.Data.MySqlClient;provider connection string='         server=xxx.net;         user id=xxx;         password=xxx;         database=xxx'" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v12.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity" />
    </providers>
  </entityFramework>

I have the feeling Entity Framework 4.4.0 is not able to recognize the tag. Can I just remove or rename the section? When I remove the section I get another exception: The underlying provider failed on Open.

Bastien Vandamme
  • 17,659
  • 30
  • 118
  • 200

2 Answers2

63

I had this issue after downgrading EF from version 6 to version 5.0.0 using Nuget. I think the issue is that the providers configuration is added when adding EF v6 but not removed after downgrade. So, you can just simply remove the content within the <providers> tags and the tags themselves and it will work fine:

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
    <parameters>
      <parameter value="v12.0" />
    </parameters>
  </defaultConnectionFactory>
</entityFramework>
mkimmet
  • 749
  • 3
  • 15
  • 27
Tran Nguyen
  • 1,341
  • 10
  • 15
  • removing works for me. If you delete the config file VS2012 recreates it with the offending tags in there again, and i have to manually remove them again. why would this be i wonder? – timothy May 21 '15 at 06:12
  • to answer my own comment - I was removing from .exe.config in the bin directory, not from the App.config file. Remove from App.config file and all is fine. – timothy May 21 '15 at 08:37
  • 1
    @timothy That's one of those triple facepalm errors that programmers do. And I just did it today..don't know where my head was. – Apostrofix Feb 11 '16 at 14:05
  • This was my same situation. I downgraded from EF 6 to 5 with Nuget. Thanks for the answer! – YeahStu Aug 30 '16 at 16:03
  • Thank you for the answer. Updating from 5 to 6 broke odata service, downgrading back to 5 generates this problem. – Hong Apr 11 '18 at 06:24
0

You need to remove the tag from your project's app.config file and not from the YourProjectName.dll.config file as it will automatically remove it from YourProjectName.dll.config after you build your project.

Note: The answer is found in the above comment itself. I have just combined the answer here.

thatskj
  • 121
  • 2
  • 7