Not sure why this is not returning my view after the task is completed and I can find much on Google as to why.
public async Task<ActionResult> GetUserAsync()
{
var value = Task.Factory.StartNew(() => _userService.GetUser("ausername"));
await Task.WhenAll(value);
return View("GetUser");
}
Ok, so after too many hours of debugging and pulling what is left of my hair out, I found the culprit. It was my WindsorActionInvoker!! A change from ControllerActionInvoker to AsyncControllerActionInvoker fixed the issue with async Task not working as intended.
I hope this helps someone.
public class WindsorActionInvoker : AsyncControllerActionInvoker
{
private readonly IKernel _kernel;
public WindsorActionInvoker(IKernel kernel)
{
_kernel = kernel;
}
protected override ActionExecutedContext InvokeActionMethodWithFilters(ControllerContext controllerContext,
IList<IActionFilter> filters,
ActionDescriptor actionDescriptor,
IDictionary<string, object> parameters)
{
foreach (IActionFilter actionFilter in filters)
{
_kernel.InjectProperties(actionFilter);
}
return base.InvokeActionMethodWithFilters(controllerContext, filters, actionDescriptor, parameters);
}
}
Was this project upgraded from a prior version? Check that any libraries you're referencing are not referencing an old version of MVC as a dependency. To fix this exact issue I...
Removed the following from my web.config:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
Ensured targetFramework is .NET 4.5
<compilation debug="true" targetFramework="4.5">
And removed a reference to the library Fluent Filters which was a legacy solution for global filters.
With those changes I was able to return a task from a controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With