[英]C# Async MVC method returns ContentResult System.Threading.Tasks.Task`1[System.Web.Mvc.JsonResult]
I'm trying to convert some methods to async and have started off with a simple example within the controller I am modifying: 我正在尝试将一些方法转换为异步方法,并以我正在修改的控制器内的一个简单示例开始:
public class MyAPIController : AsyncController
{
public async Task<JsonResult> List()
{
return Json(123456, JsonRequestBehavior.AllowGet);
}
...
}
When I test the method rather than the Json result I get the string value "System.Threading.Tasks.Task`1[System.Web.Mvc.JsonResult]" which I have verified with Fiddler and by browsing. 当我测试方法而不是Json结果时,我得到了字符串值“ System.Threading.Tasks.Task`1 [System.Web.Mvc.JsonResult]”,该值已通过Fiddler并通过浏览进行了验证。
The project has been manually upgraded to .NET45. 该项目已手动升级到.NET45。 Searches suggest that this is possibly a problem with incorrect assembly versions but a check of the project file and Process view suggests that the correct types are referenced and loaded at run time. 搜索表明这可能是程序集版本不正确的问题,但是对项目文件和“过程”视图的检查表明,在运行时已引用并加载了正确的类型。
Does anyone have any debugging tips for this? 有人对此有任何调试提示吗?
Thanks. 谢谢。
After stripping out 90% of the code to get it working and gradually adding it back in until it failed it turns out that a custom ControllerActionInvoker was being used. 剥离90%的代码以使其正常运行并逐步将其重新添加到失败之前,结果表明正在使用自定义ControllerActionInvoker。 The fix was to change the custom invoker to inherit from AsyncControllerActionInvoker and override BeginInvokeAction instead of InvokeAction. 解决方法是将自定义调用程序更改为从AsyncControllerActionInvoker继承,并覆盖BeginInvokeAction而不是InvokeAction。 AsyncControllerActionInvoker can handle both Async and sync methods. AsyncControllerActionInvoker可以处理Async和sync方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.