Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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" 

    connectionString="
      metadata=res://*/Monsters.csdl|
               res://*/Monsters.ssdl|
               res://*/Monsters.msl;
      provider=System.Data.SqlClient;
      provider connection string=&quot;
        data source=.;
        initial catalog=Monsters2;
        integrated security=True;
        pooling=False;
        multipleactiveresultsets=True;
        App=EntityFramework
      &quot;" 
      providerName="System.Data.EntityClient" 
/>

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?

like image 608
Brent Arias Avatar asked Nov 23 '11 07:11

Brent Arias


2 Answers

I had installed EF 6 which added:

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

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
like image 145
user2888722 Avatar answered Sep 17 '22 23:09

user2888722


Just copy the connection string information from your EF model project App.Config into your and watch that you do not repeat any sections (entityFramework section for example)

like image 20
Tom Avatar answered Sep 19 '22 23:09

Tom