Error: waiting requires the type to have a suitable GetAwaiter method

I copied the same piece of code from one project to another and in the first it compiles fine and in the second it doesn't.

A piece:

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

      

Mistake:

'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'? 

      

The first project is a demo created by Microsoft and is a Windows 8.1 application.

My app is a regular WPF app and targets .NET 4.5.1 and Windows 8.1 and I added a link to Windows.winmd

as described here

I don't know why the same piece of code can compile in one application and not compile in another when all the common things like references, namespaces, ... are fine. My only idea is that maybe I am referencing some older versions that are not expected yet, but I have no idea how to test this.

+3


source to share


1 answer


The error is that it IAsyncOperation

doesn't have a method GetAwaiter

. It exists in System.Runtime.WindowsRuntime.dll

which you need to add as a reference since you are using the WinRT code in a .NET environment:

System.Runtime.WindowsRuntime.dll



More details in How to use a specific WinRT API from desktop applications

+6


source







All Articles