方法从错误和的await异步特性“不能等待”System.Threading.Tasks.Task“ [英] Method Error 'Cannot await 'System.Threading.Tasks.Task' from await and async properties

查看:2678
本文介绍了方法从错误和的await异步特性“不能等待”System.Threading.Tasks.Task“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了的NuGet包异步用于.NET Framework 4,Silverlight的4和5,和Windows Phone 7.5和8。

I have installed the NuGet Package Async for .NET Framework 4, Silverlight 4 and 5, and Windows Phone 7.5 and 8.

Version 1.0.16

我使用的是Microsoft .NET 4.0,我不能升级,由于虚拟主机套餐限制。 (可悲!)

I am using Microsoft .NET 4.0 and I can not upgrade due to Web Hosting Package Restrictions. (Sadly!)

我的测试code:(我做一个LINQ到SQL查询的地方Thread.sleep代码的)

My test Code: (I am doing a Linq to SQL Query in place of Thread.Sleep)

public class Search
{
public async Task<List<Result>> GetResults(string SearchString)
{
await System.Threading.Tasks.Task.Factory.StartNew(() => Thread.Sleep(1000));
}
}

我的错误:

Cannot await 'System.Threading.Tasks.Task'

<一个href=\"http://blogs.msdn.com/b/bclteam/p/asynctargetingpackkb.aspx\">http://blogs.msdn.com/b/bclteam/p/asynctargetingpackkb.aspx有关错误的会谈,但它并不是真正的答案,因为我不使用VB,我已经做了什么解决方案描述。

http://blogs.msdn.com/b/bclteam/p/asynctargetingpackkb.aspx talks about the error but it is not really the answer as I am not using VB and I am already doing what the solution describes.


我得到一个警告:

I am getting a warning:

Warning 4   The primary reference "Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

感谢您的帮助。

推荐答案

什么是噩梦!我发现这个问题。

What a Nightmare! I have found the problem.

Microsoft.Bcl

它出现在我的情况下,该Microsoft.Bcl和Microsoft.Bcl.Async有冲突。我删除了Microsoft.Bcl和Microsoft.Bcl.Async用下面的命令:

It appears in my case that the Microsoft.Bcl and Microsoft.Bcl.Async are in conflict. I removed the Microsoft.Bcl and Microsoft.Bcl.Async with the following commands:

uninstall-package Microsoft.Bcl.Async -force

然后

uninstall-package Microsoft.Bcl -force

,然后重新安装:

and then install again:

install-package Microsoft.Bcl.Async

现在它的工作原理魅力。我不能相信吗?还不能确定,为什么Microsoft.Bcl被摆在首位离开了那里。取出后Microsoft.Bcl.Async它就会被抛在后面。到目前为止,一切工作正常。做一些更多的测试。

Now it works a charm. I cant believe this? Also not sure as to why Microsoft.Bcl was left there in the first place. After removing Microsoft.Bcl.Async it gets left behind. So far all works fine. Some more testing to be done.

如果有其他问题进行的NuGet包,你可以在你自己的风险尝试:

If others have issues with NuGet Packages, you can try at your own risk:

update-package -pre

这将尝试回滚已更新的软件包。这是我发现的问题。

This will try to roll back packages that have been updated. This is how I found the issue.


它的价值后进一步测试指出,当一个卸载Microsoft.Bcl.Async Microsoft.Bcl不会被删除。 Microsoft.Bcl可以分别进行更新,并将其显示Microsoft.Bcl.Async超出该更新可能是一个问题。当一个安装Microsoft.Bcl.Async安装Microsoft.Bcl。

Its worth noting after further testing, Microsoft.Bcl is not removed when one uninstalls Microsoft.Bcl.Async. Microsoft.Bcl can be updated separately and it appears this update outside Microsoft.Bcl.Async may be an issue. Microsoft.Bcl is installed when one installs Microsoft.Bcl.Async.

希望这会帮助别人!

这篇关于方法从错误和的await异步特性“不能等待”System.Threading.Tasks.Task“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆