【问题标题】:async/await returning exception Threading.Tasks.Task`1[System.Web.Mvc.ActionResult] Exceptionasync/await 返回异常 Threading.Tasks.Task`1[System.Web.Mvc.ActionResult] 异常
【发布时间】:2015-02-10 21:39:29
【问题描述】:

我已经使用 Async 和 Await 实现了一种 ActionMethod,结果是 Task

[Route("Newdiaries/NewTestAsync")]
public async Task<ActionResult> Index()
{
    var countryId = Nationalizator.CurrentCountryId;
    var cultureCode = DomainCulture.Current.LCID;

    var channel = GetCandidateServiceChannel("WSHttpBinding_ICandidateService");

    IndividualPersonalInformationDto res = await channel.GetNewIndividualPersonalInformationAsync(new Guid("31764EC2-663D-C996-DB46-08D11B0047E5"), countryId, cultureCode).ConfigureAwait(false);
    var model = new MyTestModel
    {
        Name = res.BusinessId
    };

    return View("NewTestIndex",model);
}

它正在抛出 System.Threading.Tasks.Task1[System.Web.Mvc.ActionResult]`

我正在使用 Visualstudio 2012 和 .Net 4.5 框架。请帮忙。

【问题讨论】:

  • 有什么异常?
  • System.Threading.Tasks.Task 不是一个例外,而是一个类。
  • 好的,我没有得到部分视图渲染,而是显示这条消息:
  • 我的问题是它显示的不是渲染部分视图结果:System.Threading.Tasks.Task`1[System.Web.Mvc.ActionResult]
  • @PradeepKumar:你确定你使用的是 ASP.NET MVC 4

标签: asp.net-mvc-4 async-await c#-5.0


【解决方案1】:

我认为问题在于您正在从 HttpContextThread 切换,请尝试删除 .ConfigureAwait(false) ,我认为它会解决您的问题:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-02
    • 1970-01-01
    相关资源
    最近更新 更多