错误:await要求类型具有合适的GetAwaiter方法

kub*_*003 3 .net c# bluetooth async-await windows-runtime

我已经将同一段代码从一个项目复制到另一个项目,在第一个项目中它编译得很好,但在第二个项目中它没有.

这件作品是:

using Windows.Devices.Bluetooth;
// a couple of lines of other code
var rfcommProvider = await RfcommServiceProvider.CreateAsync(RfcommServiceId.FromUuid(RfcommChatServiceUuid));
Run Code Online (Sandbox Code Playgroud)

错误:

'await' requires that the type 'Windows.Foundation.IAsyncOperation<Windows.Devices.Bluetooth.Rfcomm.RfcommServiceProvider>' have a suitable GetAwaiter method. Are you missing a using directive for 'System'? 
Run Code Online (Sandbox Code Playgroud)

第一个项目是由Microsoft创建的演示,它是一个Windows 8.1应用程序.

我的应用程序是正常的WPF应用程序,它的目标是.NET 4.5.1和Windows 8.1和我加了参考Windows.winmd描述这里

我不知道为什么同一段代码可能在一个应用程序中编译而在另一个应用程序中编译时,如引用,命名空间等所有常见的东西都可以.我唯一的想法是,我可能正在引用一些尚未等待的旧版本,但我不知道如何验证这一点.

i3a*_*non 7

错误是IAsyncOperation没有GetAwaiter方法.System.Runtime.WindowsRuntime.dll由于您在.Net环境中使用WinRT代码,因此您需要添加它作为参考:

System.Runtime.WindowsRuntime.dll

有关如何使用桌面应用程序中的特定WinRT API的更多信息