GlobalConfiguration does not contain a definition for Configure

asp.net-mvc asp.net-mvc-5 entity-framework

Question

I'm attempting to create an ASP.NET MVC site that uses Database First Entity Framework.

I'm using creating a new MVC 5 site in Visual Studio Professional 2013 Update 3, then adding an ADO.NET Entity Data Model from which I choose EF Designer from database.

After that, I create a connection string, select the tables to generate the framework, and all is well.

However when I compile it, I receive this error

'MyModel.GlobalConfiguration' does not contain a definition for 'Configure'

This is in Global.asax.cs and errors here

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    GlobalConfiguration.Configure(WebApiConfig.Register);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

GlobalConfiguration is automatically generated with the added entity framework for MyModel. It certainly doesn't have a Configure method.

public partial class GlobalConfiguration
{
    public int ID { get; set; }
    public long CurrentUSN { get; set; }
    public string DBVersion { get; set; }
    public long CurrentFile { get; set; }
}

I followed all of the answers here GlobalConfiguration.Configure() not present after Web API 2 and .NET 4.5.1 migration but none worked. It's a slightly different situation as this isn't an upgrade but is instead a clean project.

All Extensions and NuGet packages are up to date. I've even deleted the generated entity and reinstalled all NuGet packages to see if that helped, but no luck.

Any suggestions?

1
12
5/23/2017 12:02:39 PM

Accepted Answer

  1. Open the Package Manager Console for the Project with the error.
  2. Type in Install-Package Microsoft.AspNet.WebApi.WebHost and hit Enter.
  3. Rebuild your Project.
29
10/17/2016 5:34:24 PM

Popular Answer

It looks like there is some sort of namespace conflict with the generated code. I'm fairly weary about this change, but everything has worked thus far.

Apparently GlobalConfiguration refers to MyModel.GlobalConfiguration.

However it's really looking for System.Web.Http.GlobalConfiguration

I switched this and all is working. What a hassle

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    System.Web.Http.GlobalConfiguration.Configure(WebApiConfig.Register);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}


Related Questions





Related

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