Error CS1929: 'IAsyncOperation<>' does not contain a definition for 'GetAwaiter'

Hi.

I tried to apply Microsoft UWP BluetoothLE project to Unity.
Windows-universal-samples/Samples/BluetoothLE at main · microsoft/Windows-universal-samples · GitHub

When I worte codes as below, I got error.

    // BT_Code: BluetoothLEDevice.FromIdAsync must be called from a UI thread because it may prompt for consent.
        Windows.Devices.Bluetooth.BluetoothLEDevice  bluetoothLeDevice = await  Windows.Devices.Bluetooth.BluetoothLEDevice.FromIdAsync(bleDeviceId);

    // this is the definition of BluetoothLEDevice.FromIdAsync()
        public static extern IAsyncOperation<BluetoothLEDevice> FromIdAsync([In] string deviceId);
Assets\Scripts\my_script.cs: error CS1929: 'IAsyncOperation<BluetoothLEDevice>' does not contain a definition for 'GetAwaiter' and the best extension method overload 'AwaitExtensions.GetAwaiter(Process)' requires a receiver of type 'Process'

In player settings menu, the Api Compatibility Level wisas set to “.NET 4.x”.

What is the problem and solution?

Thanks

I solved the problem.

Resolved - Migrating from Windows Standalone to UWP - Unity Forum

Tautvydas-Zilys said,

You’re just missing “using System;” at the top of the file. GetAwaiter is an extension method for IAsyncOperation interface and it’s defined in the System namespace. Compiler requires it to use the “await” operator.

2 Likes

I was thinking of using UWP but isn’t it being deprecated (or sunsetted) soon basically?

That depends on how you look at it. It’s unlikely to ever be removed from Windows, so your application will keep working. We also still support it as of Unity 2023.2 and it will be supported in Unity 2023 LTS, which will receive updates to at least 2026.