首页 > 解决方案 > Windows UWP BLE DeviceInformation.CreateWatcher 抛出属性键语法错误

问题描述

我们有一个使用一些 UWP 蓝牙 LE UWP 功能的桌面 Windows 应用程序。我们启动观察者:

string BTLEDeviceWatcherAQSString = "(System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\")";
string[] props = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected", "System.Devices.Aep.Bluetooth.Le.IsConnectable"};
watcher = DeviceInformation.CreateWatcher(BTLEDeviceWatcherAQSString, props, DeviceInformationKind.AssociationEndpoint);

它在大多数机器上运行良好,只是我们很少有匿名错误日志:

System.Exception: Element not found. Property key syntax error. A property key must either be specified as a canonical property name (preferred) or be of the form {fmtid} pid.
at Windows.Devices.Enumeration.DeviceInformation.CreateWatcher(String aqsFilter, IEnumerable`1 additionalProperties, DeviceInformationKind kind) 

我们为 Windows 10.0.15063(即 1703)或更高版本运行此代码,因此所有属性都应由 doc 提供。

什么可能导致此错误?一些硬件配置或 Windows 10 设置?

标签: c#windowsuwpbluetooth-lowenergy

解决方案


我在 Windows WPF 桌面应用程序中看到了这个异常。原因是我忽略了检测到 Windows 10 的修订版大于 1703 版 AKA 创作者版。因此,在早期版本的 Windows 10 上运行该应用程序的任何人都会看到此错误。不幸的是,错误是如此模糊,不支持的错误会更好。


推荐阅读