Internetandi
Internetandi

Reputation: 21

C#, BLE, BT5.0 - GetGattServicesAsync hangs forever. Why and is this a known issue?

I had to implement a bluetooth low energy interface in an older Software for the communication with Bluetooth devices. It's a WPF application targeting .NET Framework 4.8. To access the Windows.Devices.Bluetooth namespaces in the Windows Runtime APIs I installed the Microsoft.Windows.SDK.Contracts NuGet package, version 10.0.22000.196, and the System.Runtime.WindowsRuntime 4.6.0 to the project managing the communication. I am developing with Visual Studio 2022, Version 17.6.1.

Use Case: devices are scanned first, one to max. four user selected devices are then connected, important recognition data is read from the devices via bluetooth and the devices are disconnected. After a user defined interval the SW reconnects to the devices, retrieves data and then disconnects again. For each selected device the connection routine is started with Task.Run and passed to the Threadpool, so it doesn't affect the UI Thread. We use custom services in our company devices with no official SIG UUIDs.

It all seems to work just fine, but on two machines with Windows 11 Version 22H2, systembuild 2261.2283, the connection routine just freezes in the line:

var gatt = await _bleDevice.GetGattServicesAsync(BluetoothCacheMode.Uncached);

The method call never returns/completes. This happens randomly. It can happen after 20 minutes, but also after 9 days. I managed to sniff the packages:

enter image description here

Normally, at this point the Microsoft-BT-Stack would exchange information on the MTU size with the device and then send the Read By Group Type Request with the UUID for GATT Primary Service Delacaration to get the services, but this never happens.

We exchanged the devices and tried different setups with one to four devices. We also tried different BT-dongles, but the error still occured. Currently a test with updated Microsoft.Windows.SDK.Contracts package (10.0.2261.755) and System.Runtime.WindowsRuntime (4.7.0) is running.

Does anybody know of this issue? And maybe even know a workaround? Any help would be appreciated!

Upvotes: 2

Views: 356

Answers (0)

Related Questions