title: System.TypeInitializationException occured in EntityFramework.dll
body: <p>Yesterday I asked a question about why my program was not creating the database as this tutorial <a href="http://www.entityframeworktutorial.net/code-first/code-first-conventions.aspx" rel="nofollow noreferrer">http://www.entityframeworktutorial.net/code-first/code-first-conventions.aspx</a> states that it should. I got some of the problems fixed, but ended up with another exception being thrown:
  An unhandled exception of type 'System.TypeInitializationException' occurred in EntityFramework.dll</p>
  
  <p>Additional information: Typeinitialiseringsfunktionen for 'System.Data.Entity.Internal.AppConfig' threw an exception.</p>
  
  <p>So if anyone has any idea why this exception gets thrown, please help :) </p>
  
  <p>Entire Exception detail:</p>
  
  <pre><code>System.TypeInitializationException was unhandled   HResult=-2146233036 Message=Typeinitialiseringsfunktionen for 'System.Data.Entity.Internal.AppConfig' udløste en undtagelse.   Source=EntityFramework   TypeName=System.Data.Entity.Internal.AppConfig   StackTrace:
         ved System.Data.Entity.Internal.AppConfig.get_DefaultInstance()
         ved System.Data.Entity.Internal.LazyInternalConnection..ctor(DbContext context, String nameOrConnectionString)
         ved System.Data.Entity.DbContext..ctor(String nameOrConnectionString)
         ved ShopEntity.ShopContext..ctor() i C:\Users\Anders\documents\visual studio 2015\Projects\ShopEntity\ShopEntity\ShopContext.cs:linje 12
         ved ShopEntity.Program.Main() i C:\Users\Anders\documents\visual studio 2015\Projects\ShopEntity\ShopEntity\Program.cs:linje 17
         ved System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
         ved System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
         ved Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
         ved System.Threading.ThreadHelper.ThreadStart_Context(Object state)
         ved System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         ved System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         ved System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
         ved System.Threading.ThreadHelper.ThreadStart()   InnerException: 
         BareMessage='connectionStrings'-element, der ikke er genkendt.
         Filename=C:\Users\Anders\documents\visual studio 2015\Projects\ShopEntity\ShopEntity\bin\Debug\ShopEntity.vshost.exe.Config
         HResult=-2146232062
         Line=15
         Message='connectionStrings'-element, der ikke er genkendt. (C:\Users\Anders\documents\visual studio 2015\Projects\ShopEntity\ShopEntity\bin\Debug\ShopEntity.vshost.exe.Config line 15)
         Source=System.Configuration
         StackTrace:
              ved System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
              ved System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object&amp; result, Object&amp; resultRuntimeObject)
              ved System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object&amp; result, Object&amp; resultRuntimeObject)
              ved System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object&amp; result, Object&amp; resultRuntimeObject)
              ved System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object&amp; result, Object&amp; resultRuntimeObject)
              ved System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
              ved System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
              ved System.Configuration.ConfigurationManager.GetSection(String sectionName)
              ved System.Data.Entity.Internal.AppConfig..ctor()
              ved System.Data.Entity.Internal.AppConfig..cctor()
         InnerException:
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace ShopEntity
  {
      class Product
      {
          public int ProductId { get; set; }
          public int Price { get; set; }
          public string ProductName { get; set; }
  
  
      }
  }
  
  
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  namespace ShopEntity
  {
      static class Program
      {
          /// &lt;summary&gt;
          /// The main entry point for the application.
          /// &lt;/summary&gt;
          [STAThread]
          static void Main()
          {
              using (var ctx = new ShopContext())
              {
                  User adminUser = new User()
                  {
                      Address = "Skejby Vænge 96A",
                      EMailAddress = "anderskloborg@gmail.com",
                      IsAdmin = 1,
                      PassWord = "12345678",
                      UserName = "Anders1234"
                  };
                  //Product Apple = new Product() { Price = 2, ProductName = "Apple" };
                  //Product Melon = new Product() { Price = 10, ProductName = "Melon" };
                  //Product Beef = new Product() { Price = 40, ProductName = "Beef" };
                  ctx.Users.Add(adminUser);
                  //ctx.Products.Add(Apple);
                  //ctx.Products.Add(Melon);
                  //ctx.Products.Add(Beef);
                  ctx.SaveChanges();
  
              }
  
  
  
  
                  Application.EnableVisualStyles();
              Application.SetCompatibleTextRenderingDefault(false);
              Application.Run(new Form1());
          }
      }
  }
  
  using System;
  using System.Collections.Generic;
  using System.Data.Entity;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace ShopEntity
  {
      class ShopContext: DbContext
      {
          public ShopContext() : base()
          {
  
          }
  
          public DbSet&lt;User&gt; Users { get; set; }
  
          public DbSet&lt;Product&gt; Products { get; set; }
  
  
      }
  }
  
  using System;
  using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace ShopEntity
  {
      class User
      {
  
          public int UserId { get; set; }
  
          [MaxLength(20)]
          public string UserName { get; set; }
  
          [MaxLength(20)]
          public string PassWord { get; set; }
          public string EMailAddress { get; set; }
  
          [MaxLength(50)]
          public string Address { get; set; }
          public byte IsAdmin { get; set; }
  
      }
  }
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
    &lt;/configSections&gt;
    &lt;startup&gt;
      &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /&gt;
    &lt;/startup&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
  &lt;/configuration&gt;
  </code></pre>