【问题标题】:await InsertAsync error in Azure Mobile Service TableController在 Azure 移动服务 TableController 中等待 InsertAsync 错误
【发布时间】:2017-02-09 16:44:22
【问题描述】:

我的代码运行良好,但现在在等待InsertAsync 函数时,我的所有TableControllers 都出现错误。这是代码:

 // POST tables/Account
    public async Task<IHttpActionResult> PostAccount(Account item)
    {
        Account current = await InsertAsync(item);
        return CreatedAtRoute("Tables", new { id = current.Id }, current);
    }

错误说: Cannot await System.Threading.Tasks.Task&lt;sampleAppService.DataObjects.Account&gt; expression.

我不知道是什么原因造成的。有什么帮助吗?

编辑

InsertAsync 函数的签名

protected virtual Task<TData> InsertAsync (TData item);

【问题讨论】:

  • 请张贴(签名)InsertAsync方法
  • @naffie 确保在项目属性中使用正确的框架 >=4.5。我进一步阅读,然后有人因为 Microsoft.Bcl 而遇到了类似的问题。检查您的依赖关系并尽可能删除 Microsoft.Bcl。
  • @Peter Bons,我添加了一个显示其签名的编辑。 Sebi,我有 4.5 的框架,但它仍然失败。它一直在与 Microsoft.Bcl 合作,所以我不确定为什么会这样。我会尝试删除它,看看是否有任何变化。

标签: c# azure xamarin.ios azure-mobile-services


【解决方案1】:

根据上面 Sebi 的建议,我所要做的就是将 .Net Framework 目标从 4.5 to 4.5.1 更改为我的例子。 这为我解决了错误。

【讨论】:

    【解决方案2】:

    假设您的 InsertAsync() 正在执行一些在内部等待的异步操作,则必须修改您的 InsertAsync() 方法签名以包含异步字:

    protected virtual async Task<TData> InsertAsync (TData item)
    {
        await dbContext.InsertAsync(item);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多