Share via

GetGattServicesAsync() throws "Value does not fall within the expected range." exception

oregonduckman 6 Reputation points
2022-03-07T19:51:06.247+00:00

I added the following code to the BluetoothLEExplorer sample and I am seeing GetGattServicesAsync() occasionally throwing "Value does not fall within the expected range." exceptions in the AdvertisementWatcher_Received event handler. Any help on this matter is appreciated.

The code was inserted right after the call to await BluetoothLEDevicesLock.WaitAsync();.

            var device = await BluetoothLEDevice.FromBluetoothAddressAsync(args.BluetoothAddress);

            if (device == null)
            {
                Debug.WriteLine("FromBluetoothAddressAsync failed");
                return;
            }
            Debug.WriteLine("++++++++++++++++++++++++FromBluetoothAddressAsync succeded");
            try
            {
                var gatt = await device.GetGattServicesAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
Developer technologies | Universal Windows Platform (UWP)

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.