My client is 2 months into developing an application using the RC version of MVC 4 and Web API. We recenly added a new developer to the team and set him up with the RTM version to see how we would fair. Right out of the gate we're getting exceptions when
registering our Web Api routes.
We're using Areas, so here's the route mapping code for our area registration:
public override void RegisterArea(AreaRegistrationContext context)
{
//Register Web API route
context.Routes.MapHttpRoute(
name: "foo_defaultapi",
routeTemplate: "foo/api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
//Register MVC route
context.MapRoute(
"foo_default",
"foo/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional });
}
Here's the exception we're seeing:
Method 'GetVirtualPath' in type 'System.Web.Http.WebHost.Routing.HostedHttpRoute' from assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
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.
Exception Details: System.TypeLoadException: Method 'GetVirtualPath' in type 'System.Web.Http.WebHost.Routing.HostedHttpRoute' from assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an
implementation.
Source Error:
Line 38: public override void RegisterArea(AreaRegistrationContext context)
Line 39: {
Line 40: context.Routes.MapHttpRoute(
Line 41: name: "foo_DefaultApi",
Line 42: routeTemplate: "foo/api/{controller}/{id}",
Yes, thanks, issues with the previous version hanging around was the inital problem. Though it wasn't in the GAC as far as I could see. Regardless, we can around that and then had to upgrade Json.Net (Newtonsoft.Json) to get past the next issue.
I have exactly this issue. I've installed VS2012, opened an existing 2010 solution with 2 ASP.NET MVC 4 RC projects and added a new ASP.NET MVC 4 project.
The new project references ASP.NET 4 installation folder in Program Files(x86) and the MapHttpRoute method is not found.
If I make a new solution and MVC 4 project, it does the same.
Existing projects using the Nuget package are fine. Removing and re-adding MVC 4 Nuget package is fine.
kylelibb
0 Points
3 Posts
Web API MapHttpRoutes broken after upgrade from RC to Release of MVC 4
Aug 22, 2012 05:00 PM|LINK
My client is 2 months into developing an application using the RC version of MVC 4 and Web API. We recenly added a new developer to the team and set him up with the RTM version to see how we would fair. Right out of the gate we're getting exceptions when registering our Web Api routes.
We're using Areas, so here's the route mapping code for our area registration:
public override void RegisterArea(AreaRegistrationContext context) { //Register Web API route context.Routes.MapHttpRoute( name: "foo_defaultapi", routeTemplate: "foo/api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }); //Register MVC route context.MapRoute( "foo_default", "foo/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }); }Here's the exception we're seeing:
Method 'GetVirtualPath' in type 'System.Web.Http.WebHost.Routing.HostedHttpRoute' from assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
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.
Exception Details: System.TypeLoadException: Method 'GetVirtualPath' in type 'System.Web.Http.WebHost.Routing.HostedHttpRoute' from assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
Source Error:
Line 38: public override void RegisterArea(AreaRegistrationContext context)
Line 39: {
Line 40: context.Routes.MapHttpRoute(
Line 41: name: "foo_DefaultApi",
Line 42: routeTemplate: "foo/api/{controller}/{id}",
Source File: C:\workspaces\Release\MyApp\Areas\Foo\FooAreaRegistration.cs Line: 40
Stack Trace:
[TypeLoadException: Method 'GetVirtualPath' in type 'System.Web.Http.WebHost.Routing.HostedHttpRoute' from assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.]
System.Web.Http.RouteCollectionExtensions.MapHttpRoute(RouteCollection routes, String name, String routeTemplate, Object defaults, Object constraints, HttpMessageHandler handler) +0
System.Web.Http.RouteCollectionExtensions.MapHttpRoute(RouteCollection routes, String name, String routeTemplate, Object defaults) +69
MyApp.Areas.Foo.FooAreaRegistration.RegisterArea(AreaRegistrationContext context) in C:\workspaces\Release\MyApp\Areas\Foo\FooAreaRegistration.cs:40
System.Web.Mvc.AreaRegistration.CreateContextAndRegister(RouteCollection routes, Object state) +105
System.Web.Mvc.AreaRegistration.RegisterAllAreas(RouteCollection routes, IBuildManager buildManager, Object state) +199
System.Web.Mvc.AreaRegistration.RegisterAllAreas(Object state) +45
System.Web.Mvc.AreaRegistration.RegisterAllAreas() +6
VRC.MRPa.MrpaApplication.Application_Start() in c:\workspaces\Release\MyApp\Global.asax.cs:42
DarrellNorto...
All-Star
86805 Points
9644 Posts
Moderator
MVP
Re: Web API MapHttpRoutes broken after upgrade from RC to Release of MVC 4
Aug 22, 2012 05:39 PM|LINK
You've got the older version still installed in the GAC. Use this command to uninstall it:
Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
kylelibb
0 Points
3 Posts
Re: Web API MapHttpRoutes broken after upgrade from RC to Release of MVC 4
Aug 22, 2012 06:48 PM|LINK
Turns out we were missing some key components of the release version of MVC 4. Had nothing to do with the MVC 4 upgrade from RC to Release.
kylelibb
0 Points
3 Posts
Re: Web API MapHttpRoutes broken after upgrade from RC to Release of MVC 4
Aug 22, 2012 06:50 PM|LINK
Yes, thanks, issues with the previous version hanging around was the inital problem. Though it wasn't in the GAC as far as I could see. Regardless, we can around that and then had to upgrade Json.Net (Newtonsoft.Json) to get past the next issue.
MyScreenName...
Member
17 Points
20 Posts
Re: Web API MapHttpRoutes broken after upgrade from RC to Release of MVC 4
Aug 30, 2012 05:51 PM|LINK
I have exactly this issue. I've installed VS2012, opened an existing 2010 solution with 2 ASP.NET MVC 4 RC projects and added a new ASP.NET MVC 4 project.
The new project references ASP.NET 4 installation folder in Program Files(x86) and the MapHttpRoute method is not found.
If I make a new solution and MVC 4 project, it does the same.
Existing projects using the Nuget package are fine. Removing and re-adding MVC 4 Nuget package is fine.
MyScreenName...
Member
17 Points
20 Posts
Re: Web API MapHttpRoutes broken after upgrade from RC to Release of MVC 4
Aug 30, 2012 06:05 PM|LINK
Okay this was down to the default RouteConfig.cs in the new project not having
using System.Web.Http;
At the top.