Pergunta

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?

Foi útil?

Solução

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;

  1. Try upgrading to the latest ELMAH - it may have fixes for async/await.
  2. 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

Outras dicas

This worked for me,

changing

public class authController : Controller

to

public class authController : AsyncController

I made the controller class that contains the async action that gave that error inherit from AsyncController class instead of the default Controller class

I found that answer here

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top