title: MVC 5 Task Parallel and ActionInvoker
body: <p>I'm working in an MVC5 application that will be handling some intense IO operations.  So we are converting methods to use the async/await TPL stuff.</p>
  
  <p>Prior to the async/await changes I registered a custom IAsyncActionInvoker which changes the Json ActionResult to a JsonNet ActionResult like in this example:</p>
  
  <p><a href="https://stackoverflow.com/questions/7109967/using-json-net-as-default-json-serializer-in-asp-net-mvc-3-is-it-possible">Using JSON.NET as the default JSON serializer in ASP.NET MVC 3 - is it possible?</a></p>
  
  <p>The trouble comes in when changing to use async/await Task where the JsonNet ActionResult is never executed.  Does anyone know how to maintain this implementation while moving to async/await Task ?</p>
  
  <pre><code> public class CustomActionInvoker : AsyncControllerActionInvoker
  {
      protected override ActionResult InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary&lt;string, object&gt; parameters)
      {
          ActionResult invokeActionMethod = base.InvokeActionMethod(controllerContext, actionDescriptor, parameters);
  
          if (invokeActionMethod is JsonResult)
          {
              return new JsonNetResult(invokeActionMethod as JsonResult);
          }
  
          return invokeActionMethod;
      }
  }
  
  
  
  
   public class HomeController : Controller
  {
      // THIS WORKS!
      public ActionResult Test()
      {
          return Json(new
          {
              Property1 = "blah",
              Property2 = "test"
          }, JsonRequestBehavior.AllowGet);
      }
  
      // THIS DOES NOT FIRE MY CUSTOM ACTION INVOKER
      // IT RUNS THE DEFAULT
      public async Task&lt;ActionResult&gt; Test()
      {
          await Task.Run(() =&gt;
          {
              Thread.Sleep(1000);
          });
  
          return Json(new
          {
              Property1 = "blah",
              Property2 = "test"
          }, JsonRequestBehavior.AllowGet);
      }
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated guys!</p>