It seems that a few people (for example, here and here ) have encountered problems with binding the MVC4 model for ApiControllers , but none of them seem to cope with the problem that I see.
All I really would like to do is change the array binding behavior for integer lists. So say that I had a request type:
public class MyRequestModel { public List<long> ListOfIntegers { get; set; } ... }
And a GET API method like this:
public ResultsResponseModel Get(MyRequestModel request) {
Basically I want to say /api/results/?listOfIntegers=1+2+3+4+5 and have this solution for the List<long> property.
I tried my usual model-bound tricks, but, like most web APIs in MVC4, it has a completely separate model-binding path.
The most that I got is to use the System.Web.Http.ModelBinding.ModelBinder attribute on MyRequestModel and create a binding to a model that is "implemented" by System.Web.Http.ModelBinding.IModelBinder . This consistently gives an object reference exception with stack traces that never touch my code.
Has anyone hit this? Any thoughts on what to try next?
UPDATE Here's the stack trace I grabbed in my custom ExceptionFilterAttribute :
Object reference not set to an instance of an object. at System.Web.Http.ModelBinding.DefaultActionValueBinder.BindParameterValue(HttpActionContext actionContext, HttpParameterBinding parameterBinding) at System.Web.Http.ModelBinding.DefaultActionValueBinder.<>c__DisplayClass1.BindValuesAsync>b__0(RequestContentReadKind contentReadKind) at System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass38.<ToAsyncVoidTask>b__37() at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
asp.net-mvc asp.net-web-api asp.net-mvc-4
Brandon linton
source share