Bluetooth LE GattDeviceServicesResult TypeLoadException from WPF application

我的梦境 提交于 2019-12-11 04:38:01

问题


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?

来源:https://stackoverflow.com/questions/47662026/bluetooth-le-gattdeviceservicesresult-typeloadexception-from-wpf-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!