title: Unable to retrieve metadata for 'MyService.Entities.Email'. The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception
body: <p>I am trying out the new Visual Studio 11 Beta with MVC 4.0 and EF 4.3.1.</p>
  
  <p>When adding a controller I get the following message "Unable to retrieve metadata for 'MyService.Entities.Email'. The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception"</p>
  
  <p>Repro</p>
  
  <p>I have a basic a solution which has an Entities project (MyService.Entities) and and MVC project (MyService.Website).</p>
  
  <p>In the Entities project I have the bare bones for code first with a class for "Email" and a class for the DbContext. The two classes look like:
  <strong>EntitiesDb</strong></p>
  
  <pre><code>   namespace MyService.Entities
  {
      public class EntitiesDb : DbContext
      {
          public EntitiesDb(string nameOrConnectionString)
              : base(nameOrConnectionString)
          { }
  
          public EntitiesDb()
          {
          }
  
          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              // Sets up the defaults for the model builder
              // Removes the metadata being written to the database, This is being depreciated anyhow 
              modelBuilder.Conventions.Remove&lt;IncludeMetadataConvention&gt;();
  
              // Sets the table names so that they are named as a none plural name 
              modelBuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;();
  
              // Creates the database from scratch when it builds
              base.OnModelCreating(modelBuilder);
          }
  
          public DbSet&lt;Email&gt; Emails { get; set; }
      }
  }
  </code></pre>
  
  <p><strong>Email</strong></p>
  
  <pre><code>namespace MyService.Entities
  {
      public class Email
      {
          public Email()
          {
          }
  
          [Key, DatabaseGenerated(System.ComponentModel.DataAnnotations.DatabaseGeneratedOption.Identity)]
          public int EmailId { get; set; }
          public string Subject { get; set; }
          public string BodyHTML { get; set; }
      }
  }
  </code></pre>
  
  <p>I have referenced the MyService.Entities project in the MyService.Website MVC project and set the Connection String to fit my Database name</p>
  
  <pre><code>&lt;add name="EntitiesDb" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=EntitiesDb;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p>When I go to create the MVC scaffolding by doing the following:</p>
  
  <ul>
  <li><em>Right click</em> on <strong>Controllers</strong> folder > <strong>Add</strong> > <strong>Controller</strong></li>
  <li>Set controller name to be <strong>EmailController</strong></li>
  <li>Set Template to <strong>Controller with read/write actions and views, using Entity Framework</strong></li>
  <li>Set Model class to <strong>Email(MyService.Entities)</strong></li>
  <li>Set Data context class to <strong>EntitiesDb (MyService.Entities)</strong></li>
  <li>Set Views as <strong>Razor</strong></li>
  </ul>
  
  <p>It shows a message of  </p>
  
  <p><strong>"Unable to retrieve metadata for 'MyService.Entities.Email'. The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception"</strong></p>
  
  <p>The confusing thing is that it worked initially and then I started to add some more entities and Properties into the database and then it wouldn't allow me. I've now scaled right back and it is still doing it.</p>
  
  <p>I have tried a few things after looking on the forums:</p>
  
  <ul>
  <li>Checking the Connection string is correct in MVC Project Adding a</li>
  <li>Connection string in the Entities Project </li>
  <li>Reinstalled Visual Studio 11 Beta in case any updates have affected it</li>
  <li>Checking that the references match (they are both EntityFramework
  Version 4.3.1.0)</li>
  <li>Dropping the database to rebuild (Now I don't have one ;o))</li>
  </ul>
  
  <p>Is this a bug in VS11? Am I missing a reference to the metadata somewhere?</p>
  
  <p>Any help much appreciated.</p>
  
  <p><strong>EDIT:
  By un-installing the EntitiesFramework and re-installing the NuGet package fixed the problem.</strong></p>