I'm using the FromUri attribute to bind query string parameters to a custom model in a Web Api application.
There are 2 scenarios where I found the error message returned by the ApiController's ModelState is empty.
This happens when I enter the value '#' for a nullable integer and when I enter 2 identical parameters into the query string.
I'm expecting a meaningful message to be returned e.g. "The value '#' is not valid for NullableInteger" and "Duplicate entries in query string".
Comments: 1. The "#" scenario is interesting. I'm assuming you had it url encoded when - if not, it's going to be treated as the fragment identifier. If you have, the TypeConverter that WebAPI and Mvc use, attempts to treat the value as a hex string. If your query string looked like ?value=%2CFF (unencoded value: #FF), you'd have read the value as the int value 255 in your action. Simply passing the token "%2C" results in an ArgOutOfRangeException being recorded in the ModelState. This is quirky behavior, but I doubt we'd able to change it now. 2. For the multiple parameter scenario, Mvc does not throw an exception, instead choosing to pick the first parameter silently. However I did notice around having more than one identical parameters in the query string. We'll follow up with it in - https://aspnetwebstack.codeplex.com/workitem/1563 since it feels like a separate issue that needs to be triaged.
There are 2 scenarios where I found the error message returned by the ApiController's ModelState is empty.
This happens when I enter the value '#' for a nullable integer and when I enter 2 identical parameters into the query string.
I'm expecting a meaningful message to be returned e.g. "The value '#' is not valid for NullableInteger" and "Duplicate entries in query string".
Comments: 1. The "#" scenario is interesting. I'm assuming you had it url encoded when - if not, it's going to be treated as the fragment identifier. If you have, the TypeConverter that WebAPI and Mvc use, attempts to treat the value as a hex string. If your query string looked like ?value=%2CFF (unencoded value: #FF), you'd have read the value as the int value 255 in your action. Simply passing the token "%2C" results in an ArgOutOfRangeException being recorded in the ModelState. This is quirky behavior, but I doubt we'd able to change it now. 2. For the multiple parameter scenario, Mvc does not throw an exception, instead choosing to pick the first parameter silently. However I did notice around having more than one identical parameters in the query string. We'll follow up with it in - https://aspnetwebstack.codeplex.com/workitem/1563 since it feels like a separate issue that needs to be triaged.