GetVirtualPath on HttpRoute currently has this code:
IHttpRouteData routeData = request.GetRouteData();
if (routeData == null)
{
return null;
}
That's wrong. In MVC we don't require route data to generate a link. Instead, we just treat it as if the route data had an empty collection.
This behavior is particularly problematic for MediaTypeFormatters that need to serialize errors and use GetVirtualPath in their implementation. If routing itself fails, no route data property will be set. When the media type formatter is asked to serialize the resulting error, it won't be able to use GetVirtualPath.
Comments: verified
IHttpRouteData routeData = request.GetRouteData();
if (routeData == null)
{
return null;
}
That's wrong. In MVC we don't require route data to generate a link. Instead, we just treat it as if the route data had an empty collection.
This behavior is particularly problematic for MediaTypeFormatters that need to serialize errors and use GetVirtualPath in their implementation. If routing itself fails, no route data property will be set. When the media type formatter is asked to serialize the resulting error, it won't be able to use GetVirtualPath.
Comments: verified