"Unable to Retrieve Metadata...Config System Failed to Initialize" in MVC "Add Controller"

asp.net-mvc entity-framework visual-studio


From scratch, I made a new solution with two projects: one was MVC 3 and the other a supporting EF 4.2 project. The whole thing builds successfully. From the MVC project I open the "Add Controller" dialogue and have it generate code based on the context and model I select from the supporting EF project. The "add controller" dialogue fails with the message:

Unable to retrieve metadata for 'MyModelClass'. Configuration system failed to initialize.

I've noticed that the "add controller" dialogue is actually attempting to fetch the database connection string from its web.config file. First, this strikes me as goofy-ish, since the supporting EF project already has an app.config with the connection string. But never-minding that, the best I can figure is that the connection string in the web.config is bad somehow. This is what it looks like:

<add name="Monsters2Entities" 

      provider connection string=&quot;
        data source=.;
        initial catalog=Monsters2;
        integrated security=True;

The connection string doesn't actually have all the ridiculous line breaks and indentation - I'm just trying to make it easier to read. Anyway, that connection string is basically identical to the connection string used in the supporting EF project upon which it is modelled. How do I correct the situation, to make the "add controller" dialgoue happy?

11/23/2011 7:55:04 AM

Popular Answer

I had installed EF 6 which added:

    <provider invariantName="System.Data.SqlClient" 
        type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />

In my config file. I had other scaffolding issues and so decided to fall back to Ef 5. After uninstalling EF 6 and reinstalling EF 5 I deleted the from the config and then I was able to build my new controller. I discovered this by using the

PM> Update-Database –Verbose
5/7/2014 1:28:13 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow