GlobalConfiguration does not contain a definition for Configure

35,468

Solution 1

  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.

Solution 2

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);
}

Solution 3

1 - Make sure the files in your Team Explorer, if perform checkin;

2 - Check for old files in "packages" concerning the dll WebAPI such as the folder "Microsoft.AspNet.WebApi.WebHost.5.2.3" folder, if there are clear;

3 - After leaving everything clean install the project;

Good luck!!!!!

Share:
35,468
Kirk
Author by

Kirk

Nothing to add

Updated on October 18, 2020

Comments

  • Kirk
    Kirk over 3 years

    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?

  • Syed Mohamed
    Syed Mohamed almost 6 years
    We can also install the same from NuGet package manager UI too
  • boatcoder
    boatcoder about 3 years
    Agreed, what a HUGE hassle. You would think MS could do a better job with package names and/or keep them in sync with one another.
  • Karthic G
    Karthic G almost 3 years
    I tried but not worked for me, I used Net40 Application,Is there any changes in NET40