I'm building a WPF app in Visual Studio 2017, running Windows 10 version build 10586.164, and trying to connect to a bluetooth LE device. I've added references to:
- System.Runtime.InteropServices.WindowsRuntime.dll
- System.Runtime.WindowsRuntime.dll
- System.Runtime.WindowsRuntime.UI.Xaml.dll
from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5. I also added references to:
- C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Facade\Windows.WinMD
- C:\Program Files (x86)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd
- C:\Program Files (x86)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.UniversalApiContract\5.0.0.0\Windows.Foundation.UniversalApiContract.winmd
When I run this code:
public async Task Connect()
{
_device = await BluetoothLEDevice.FromIdAsync("12:34:56:78:90:AB");
var svcresult = await _device.GetGattServicesAsync();
foreach (var service in svcresult.Services)
{
var chrresult = await service.GetCharacteristicsAsync();
foreach(var chr in chrresult.Characteristics)
{
var dscresult = await chr.GetDescriptorsAsync();
}
}
}
It immediately fails, before even attempting to connect, with a type load exception for Windows.Devices.Bluetooth.GenericAttributeProfile.GattDeviceServicesResult. I can build and I can see the type in the object browser just fine. Do I need the creators update to make any of this work, or am I missing something else?