DefaultInlineConstraintResolver Error in WebAPI 2 DefaultInlineConstraintResolver Error in WebAPI 2 asp.net asp.net

DefaultInlineConstraintResolver Error in WebAPI 2


The error means that somewhere in a Route, you specified something like

[Route("SomeRoute/{someparameter:string}")]

"string" is not needed as it is the assumed type if nothing else is specified.

As the error indicates, the DefaultInlineConstraintResolver that Web API ships with does not have an inline constraint called string. The default supported ones are the following:

// Type-specific constraints{ "bool", typeof(BoolRouteConstraint) },{ "datetime", typeof(DateTimeRouteConstraint) },{ "decimal", typeof(DecimalRouteConstraint) },{ "double", typeof(DoubleRouteConstraint) },{ "float", typeof(FloatRouteConstraint) },{ "guid", typeof(GuidRouteConstraint) },{ "int", typeof(IntRouteConstraint) },{ "long", typeof(LongRouteConstraint) },// Length constraints{ "minlength", typeof(MinLengthRouteConstraint) },{ "maxlength", typeof(MaxLengthRouteConstraint) },{ "length", typeof(LengthRouteConstraint) },// Min/Max value constraints{ "min", typeof(MinRouteConstraint) },{ "max", typeof(MaxRouteConstraint) },{ "range", typeof(RangeRouteConstraint) },// Regex-based constraints{ "alpha", typeof(AlphaRouteConstraint) },{ "regex", typeof(RegexRouteConstraint) }


One more thing if you can't use int, bool or any other constraint it is key sensitive and you need to remove any white spaces.

//this will work[Route("goodExample/{number:int}")][Route("goodExampleBool/{isQuestion:bool}")]//this won't work[Route("badExample/{number : int}")][Route("badExampleBool/{isQuestion : bool}")]


I also got this error when I left a space between the variable name and the variable type in the route, like so:

[HttpGet][Route("{id: int}", Name = "GetStuff")]

It should be the following:

[HttpGet][Route("{id:int}", Name = "GetStuff")]