更正.NET中BLE的GattDeviceServicesResult的库或运行时



UPDATE我现在有理由相信,您不能在Enterprise LTSB上使用Windows Creator,因为版本不够高,无法更新!如果有人能证实这一点,并说明我应该如何开发蓝牙应用程序,因为我可以使用Creator,那将不胜感激。

"找不到Windows运行时类型'Windows.Device.Bluetooth.GenericAttributeProfile.GatDeviceServicesResult'">

我在我的开发人员机器上开发了一些示例代码,通过C#/.Net中的BLE(蓝牙低能耗(进行通信。当我将此发布文件夹转移到另一台机器并运行程序时,当我尝试启动BLE通信时,我会收到上面的消息。我猜我丢失了一些密钥库.dll(或.NETCore或.Net Framework(,但怎么了?我找遍了,找不到答案。

一个可能有用的线索(或者可能不相关(是,在我的项目中,我在目录C:\Program Files(x86(\reference Assemblies\Microsoft\Framework.NETCore\v4.5.1 \ System.Runtime.WindowsRuntime.dll中引用了System.Runtime.WindowsRuntime另一台机器没有v4.1.1,但只有v4.5。然而,当我尝试安装v4.5.1时,我被告知我已经有了一个更新的版本!也许有人可以告诉我如何在机器上获得.netcore v4.5.1?

谢谢,Dave

更多信息在原始项目中,有一个引用"Windows",路径为C:\Program Files(x86(\Windows Kits\10\UnionMetadata\10.0.17134.0\Windows.winmd如果对此使用对象浏览器,您将看到Windows.Devices.Bluetooth.GenericAttributeProfile.GatDeviceServicesResult这个相同的文件(相同的版本(也在我试图让代码运行的系统上。不确定为什么它在运行时没有"看到"它。

显然,其他人也有这个问题。请参阅:蓝牙LE GattDeviceServicesResult TypeLoadException from WPF application

更多基于研究的信息我在生产机器上安装了Visual Studio,认为这将消除我的开发人员机器和生产机器之间的一个差异。仍然没有运气。然而,我要指出的是,剩下的区别之一是我的开发人员机器有Windows 10 Pro。生产机器(平板电脑(具有Windows 10 Enterprise 2016 LTSB

Windows 10 Enterprise似乎不支持Windows.Devices.Bluetooth命名空间中的许多方法。我找到的解决方案需要Windows 10 Enterprise用户配对他们的BLE设备。这允许我们使用过时的BluetoothLEDevice.GattServices属性。我们捕获了TypeLoadException,并返回到Windows 10 Enterprise中支持的方法。

private async Task<IReadOnlyCollection<GattDeviceService>> GetGattService(BluetoothLEDevice device, Guid uuid)
{
try
{
// Try to get the services async first
return await GetGattServicesAsync(device, uuid);
}
catch(TypeLoadException e)
{
// Not supported in version of windows. Fall back to old way
return GetGattDeviceServices(device, uuid);
}
}
private async Task<IReadOnlyList<GattDeviceService>> GetGattServicesAsync(BluetoothLEDevice device, Guid uuid)
{
var result = await Device.GetGattServicesForUuidAsync(uuid);
if(result.Status == GattCommunicationStatus.Success)
{
return result.Services;
}
return null;
}
private IReadOnlyList<GattDeviceService> GetGattDeviceServices(BluetoothLEDevice device, Guid uuid)
{
var result = device.GattServices.Where(s => s.Uuid == uuid);
if(result != null)
{
return result.ToList().AsReadOnly();
}
return null;
}

当我们试图从服务中获取特征时,也需要这样做。我们不调用GattDeviceService.GetCharacteristicsForUuidAsync,而是调用GattDeviceService.GetAllCharacteristics()。我还发现一些PC不支持任何BluetoothLEDevice.GetDeviceSelector()方法的实例,这导致创建观察程序时出现问题。必须将设备配对有点不方便。不幸的是,我找不到任何关于这方面的文件。除了这里的几个视频,他们讨论不再需要配对BLE设备,这让我相信它在LTSB中不受支持。

最新更新