title: EF 4.1 RC - 'System.Data.Entity.IDatabaseInitializer`1[TContext]' violates the constraint of type parameter 'TContext'
body: <p>I've just updated my project (using NuGet) to Entity Framework 4.1 RC and receives this error msg:</p>
  
  <blockquote>
    <p>GenericArguments[0],
    'Notesnhac.Library.NotesnhacContext',
    on
    'System.Data.Entity.IDatabaseInitializer`1[TContext]'
    violates the constraint of type
    parameter 'TContext'.</p>
    
    <p>Description: An unhandled exception
    occurred during the execution of the
    current web request. Please review the
    stack trace for more information about
    the error and where it originated in
    the code. </p>
    
    <p>Exception Details:
    System.TypeLoadException:
    GenericArguments[0],
    'Notesnhac.Library.NotesnhacContext',
    on
    'System.Data.Entity.IDatabaseInitializer`1[TContext]'
    violates the constraint of type
    parameter 'TContext'.</p>
    
    <p>Source Error: </p>
    
    <p>Line
    114:          DependencyResolver.SetResolver(new
    StructureMapDependencyResolver(container));
    Line 115:         #endregion Line 116:        }
    Line 117: } Line 118:}</p>
    
    <p>Source File: C:\projects\Kenny
    Projects\Notesnhac\Notesnhac.Site\Global.asax.cs
    Line: 116 </p>
    
    <p>Stack Trace: </p>
    
    <p>[TypeLoadException:
    GenericArguments[0],
    'Notesnhac.Library.NotesnhacContext',
    on
    'System.Data.Entity.IDatabaseInitializer`1[TContext]'
    violates the constraint of type
    parameter 'TContext'.]<br>
    Notesnhac.Site.MvcApplication.Application_Start()
    in C:\projects\Kenny
    Projects\Notesnhac\Notesnhac.Site\Global.asax.cs:116</p>
    
    <p>Version Information: Microsoft .NET
    Framework Version:4.0.30319; ASP.NET
    Version:4.0.30319.225</p>
  </blockquote>
  
  <p>It says the error is on line 116 but I don't think it's where the error is. Here's a snip of the code where it says the error, line #116 is the curly brace right after <code>#endregion</code>:</p>
  
  <pre><code>protected void Application_Start()
  {
      // Initalizes the database
      System.Data.Entity.Database.SetInitializer&lt;NotesnhacContext&gt;(new ContextInitializer());
  
      AreaRegistration.RegisterAllAreas();
      RegisterGlobalFilters(GlobalFilters.Filters);
      RegisterRoutes(RouteTable.Routes);
  
      AutoMapperConfig.CreateMappings();
  
      ControllerBuilder.Current.DefaultNamespaces.Add("Notesnhac.Site.Controllers");
  
      #region StructureMap IoC
      IContainer container = new Container(x =&gt;
      {
          x.For&lt;IControllerActivator&gt;().Use&lt;StructureMapControllerActivator&gt;();
          x.Scan(s =&gt;
          {
              s.Assembly("Notesnhac.Library");
              s.TheCallingAssembly();
              s.AddAllTypesOf&lt;IController&gt;().NameBy(type =&gt; type.Name.Replace("Controller", "").ToLower());
              s.WithDefaultConventions();
          });
      });
      DependencyResolver.SetResolver(new StructureMapDependencyResolver(container));
      #endregion
  }
  </code></pre>
  
  <p>Thanks.</p>