This project is read-only.

Custom IActionInvoker and async Action

Sep 11, 2012 at 6:07 AM

I'm using NInject as the default container and the NInjectResolver class on an MVC4 project. Injection works great.

Now I'm trying to replace the default IActionInvoker in order to provide custom JSON serialization as shown here.

This seems to work OK if the action returns JsonResult but it chokes on Task<JsonResult> (even if I bind IActionInvoker to the default ControllerActionInvoker).

When I convert it to an async action, the action returns (instead of JSON), this text: System.Threading.Tasks.Task<System.Web.Mvc.JsonResult> - like calling ToString() on it.

How do I go about fixing this?

This is from an unanswered SO question, you're welcome to answer there too if you'd like the added rep:

Sep 11, 2012 at 6:08 PM

Since you are working with Task-based async, you'll have to look at injecting an instance of AsyncControllerActionInvoker.