简体   繁体   中英

Asp.NET MVC 4 WebApi Upgrade - RC to 4.0.30506.0

I'm running into an issue that many others seemed to have back when the first production release Asp.NET WebApi was introduced and people were upgrading to it from the release candidate edition...

I've been day's trying every solution I found posted on the web with no luck, though I have a much better understanding of the situation now, and think I've narrowed down the problem.

Specifically, it appears that my app (weather its deployed to my local IIS server, or run in the development server) is using the older System.Web.Http assembly.

The very second line of the Application_Start() method fails with an exception

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();

    **WebApiConfig.Register(GlobalConfiguration.Configuration);**
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

which calls the Register method from the template-included WebApiConfig.cs file/class:

public static void Register(HttpConfiguration config)
{
    config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );
}

where the call config.Routes.MapHttpRoute() causes the following exception:

Method not found: 'System.Web.Http.Services.DependencyResolver System.Web.Http.HttpConfiguration.get_ServiceResolver()'.

Server stack trace: 
at System.Web.Http.GlobalConfiguration.<.cctor>b__0()
at System.Lazy`1.CreateValue()

Exception rethrown at [0]: 
at System.Web.Http.GlobalConfiguration.<.cctor>b__0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at System.Web.Http.GlobalConfiguration.get_Configuration()
at MvcApplication2.WebApiApplication.Application_Start() 
in C:\Projects\TestArea\ASP_MVC\4\MvcApplication2\Global.asax.cs:line 21

Things I've done so far were:

  • Reinstall all versions of .NET
  • Remove System.Web.Http from GAC
  • Made sure the project references pointed to the WebApi directories, and not the os's .NET assemblies
  • Made sure the project references were set to "Copy Local"
  • Removed IIS's temp files from c:\\windows\\system32\\inetsrv\\ and c:\\inetpub
  • Ran c:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\aspnet_regiis.exe
  • Updated all WebApi related packages through NuGet
  • Stopped and started IIS and Site
  • Rebooted

The ServiceResolver method doesn't exist in the normal .NET System.Web.Http, only in the WebApi version of System.Web.Http, that's why I figured its referencing the wrong assembly.

I'm just don't know what else to do. Any help is much appreciated. Thank you.

Since Samus found the answer himself, I will just post it here as the official answer.

I believe the solution is to check the Output window for various DLL's that are loaded, look for versions that are still using the RC version, find their location and remove them.

In his case, it was because the RC apparently added some DLL's to the GAC (this is no longer done in the release version of MVC4, as they are all bin-deployed).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM