I'm having an issue with the BluetoothLEAdvertisementDataSection.BluetoothLEAdvertisementDataSection class from the Windows 10 Bluetooth Low-energy (BLE) API.
If I check the length of the IBuffer
member Data
using this code:
var myDataSection = new BluetoothLEAdvertisementDataSection();
Debug.WriteLine($"Data Capacity: {myDataSection.Data.Capacity}"); //Looks like SO needs to update for C# 6.0
I get the expected output:
Data Capacity: 29
For more info on BLE packets, I recommend visiting this great blog post.
Now let' say I've declared a byte[]
called myPayload
which is 29 bytes long. The following code throws an exception:
DataWriter writer = new DataWriter();
writer.WriteBytes(myPayload);
myDataSection.Data = writer.DetachBuffer(); //throws ArgumentException
The ArgumentException
very helpfully suggests that
"Value does not fall within the expected range."
In fact, any size for myPayload
of 20+ bytes results in the same error. If I make it 19 bytes long, however, I get no errors.
Yes, I was very upset when this answer did not help.