Async Await MVC Action returning Task instead of ActionResult

asp.net-mvc-4, async-await, elmah

Solution

The `ErrorHandlingControllerFactory` from ELMAH returns a custom action invoker which it uses to make sure its `HandleErrorWithElmahAttribute` is applied to the controller. It never supplies an async action invoker so it doesn't understand async/await.

Two workarounds;

- Try upgrading to the latest ELMAH - it may have fixes for async/await.

- Remove the call to `ControllerBuilder.Current.SetControllerFactory(new ErrorHandlingControllerFactory())` and simply add `HandleErrorWithElmahAttribute` to the global filters using `GlobalFilters.Filters.Add(new HandleErrorWithElmahAttribute());`

Cheers, Dean

Problem

I have an action as follows: ``` public async Task<ActionResult> Pair(string id) { try { DocuSignAPIManager docuSignAPIManager = new DocuSignAPIManager(); DocuSignEsignatureAuthContainer authContainer = await docuSignAPIManager.Pair(User.Identity.Name, id).ConfigureAwait(false); DocuSignManager.Instance.Pair(User.Identity.Name, authContainer); } catch(Exception e) { ErrorManager.Instance.LogError(e); } return new HttpStatusCodeResult(200); } ``` When the action is called all of the logic is executed, however instead of an HTTP Status 200 code, I receive the following: ``` System.Threading.Tasks.Task`1[System.Web.Mvc.ActionResult] ``` For testing I'm just calling the action from a web browser using the following URL: ``` http://localhost:20551/CharteredSurveyor/Pair/password ``` I really don't understand what the problem is - can anyone help?

Original source