Error Customizing MVC5 Routes

2

The error occurs in the RegisterRoutes method in RouteConfig.cs on the

routes.MapMvcAttributeRoutes();

When running in the browser:

* The built-in constraint of type 'DefaultInlineConstraintResolver' could not resolve the following built-in constraint: 'string'. *

  

[HttpException (0x80004005): The built-in constraint resolves of type   'DefaultInlineConstraintResolver' could not resolve the following   built-in constraint: 'string'.]
  System.Web.HttpRuntime.FirstRequestInit (HttpContext context) +10042604   System.Web.HttpRuntime.EnsureFirstRequestInit (HttpContext context) +95   System.Web.HttpRuntime.ProcessRequestNotificationPrivate (IIS7WorkerRequest   wr, HttpContext context) +254

    
asked by anonymous 18.01.2018 / 21:55

1 answer

3

This error means that somewhere on a Route, you have specified something like

[Route("AlgumaRota/{algumparametro:string}")]

The inline string constraint is not required because it is already the assumed type from the URL. Even such inline constraint is not available by DefaultInlineConstraintResolver , as the error tells you.

The Route Constraints section provides a table that lists all supported constraints.

To solve your problem, just remove the string

[Route("AlgumaRota/{algumparametro}")]
    
18.01.2018 / 23:06