unable to retrieve metadata for unrecognized element providers

Mohamed Naguib picture Mohamed Naguib · Jan 22, 2014 · Viewed 18.8k times · Source

I get a message error whenever I try to add a controller with Entity framework template but I keep getting a error message

    unable to retrieve metadata for 'path' unrecognized element providers. 
         (C:\Users\user\appdata\local\Temp-mp6124.tmp line 78)

I know it's something related to connection string so here is my connection string

  <connectionStrings>
    <add name="NoktatyContext" connectionString="Data Source=(localdb)\v11.0; Initial Catalog=NoktatyContext-20140122154208; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|NoktatyContext-20140122154208.mdf" providerName="System.Data.SqlClient" />
  </connectionStrings>

Answer

macoms01 picture macoms01 · Jan 28, 2014

I was able to fix this issue by removing the <providers> section of the configuration file.

This:

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  <providers>
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  </providers>
</entityFramework>

Becomes this:

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>

I had this issue this morning and just found the fix. If you don't specify the database (and provider I guess) EF will default to SQL Server Express.