HttpRoute.GetRouteData truncates the Uri in the request message to calculate the relative request Uri, but in certain cases, for example when the request Uri is equal to the virtualPathRoot, the startIndex parameter points of the call to Substring points beyond the end of the string and the call will fail.
Comments: The scenario is that, with a Hypermedia API, you can be in a situation in which the resource representation that you're receiving (in a PUT or POST request) contains a URL to another resource that you need to parse. For example, if I'm receiving a representation of a person resource to put in my database, and that representation contains the URL of that person's manager, I need to parse that URL according to the Route that routes requests to such URI, so that I can capture the route data and get the internal ID of the manager to store in the database. Now, when that URL does not match the route that I pass in my request to get the route data, it simply returns null which is fine, because it tells me that I'm not looking at a URL that identifies a manager's person resource that belongs to my application, so I can handle that appropriately. But really, any URL might have been passed, and I stumbled upon this by accident, really. I should either get the RouteData or I should get null, but an exception is something I did not expect.
Comments: The scenario is that, with a Hypermedia API, you can be in a situation in which the resource representation that you're receiving (in a PUT or POST request) contains a URL to another resource that you need to parse. For example, if I'm receiving a representation of a person resource to put in my database, and that representation contains the URL of that person's manager, I need to parse that URL according to the Route that routes requests to such URI, so that I can capture the route data and get the internal ID of the manager to store in the database. Now, when that URL does not match the route that I pass in my request to get the route data, it simply returns null which is fine, because it tells me that I'm not looking at a URL that identifies a manager's person resource that belongs to my application, so I can handle that appropriately. But really, any URL might have been passed, and I stumbled upon this by accident, really. I should either get the RouteData or I should get null, but an exception is something I did not expect.