Error DefaultInlineConstraintResolver in WebAPI 2

I am using Web API 2 and I get the following error when I send a POST to my API method using IIS 7.5 in my local field.

The inline constraint resolver of type 'DefaultInlineConstraintResolver' was unable to resolve the following inline constraint: 'string'. Line 21: GlobalConfiguration.Configuration.EnsureInitialized(); 

None of my APIs work using IIS. However, I can run my API project in Visual Studio using IIS Express and successfully make a POST for my login API, but when I try to make a GET request to another API call, I get a constraint recognizer error.

To fix this problem, I created a new Web API 2 project in Visual Studio and started importing the existing APIs into the new project one at a time and running them to make them work. Using IIS Express with this new project, I get the exact same results as in my existing API project.

What am I missing here? Even with a completely new project, I cannot make GET requests without encountering this issue with permissions.

+83
c # api iis asp.net-web-api
May 01 '14 at 16:30
source share
3 answers

The error means that somewhere in the route you specified something like

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

a "string" is not needed because it is the intended type if nothing is specified.

As the error indicates, the DefaultInlineConstraintResolver that comes with the Web API does not have a built-in restriction called string . The supported defaults are as follows:

 // 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) } 
+144
May 01 '14 at 16:40
source share

One more thing, if you cannot use int, bool or any other restriction, it is sensitive to keys and you need to remove any spaces.

 //this will work [Route("goodExample/{number:int}")] [Route("goodExampleBool/{isQuestion:bool}")] //this won't work [Route("badExample/{number : int}")] [Route("badExampleBool/{isQuestion : bool}")] 
+21
Feb 01 '16 at 10:27
source share

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

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

It should be the following:

 [HttpGet] [Route("{id:int}", Name = "GetStuff")] 
+3
Oct 19 '16 at 22:49
source share



All Articles