【问题标题】:TargetInvocationException when using uwp bluetooth APIs in .NET 5 winforms app在 .NET 5 winforms 应用程序中使用 uwp 蓝牙 API 时出现 TargetInvocationException
【发布时间】:2021-07-27 17:09:19
【问题描述】:

代码在Windows 10 上运行良好,
但是在我的.NET 5 winforms 应用程序中使用 uwp 蓝牙 API 时,我在Windows 8.1 中得到了TargetInvocationException

内部异常是

Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))

代码:

private BluetoothLEAdvertisementWatcher BTWatch = new BluetoothLEAdvertisementWatcher();

在我的项目中,我添加了对“UwpDesktop-Updated”包的引用,并且我的 Windows 8.1 机器上安装了 windows SDK 10.0.17763.132。

让我知道如何解决在 Windows 8.1 上出现的这个问题

【问题讨论】:

    标签: c# .net winforms uwp


    【解决方案1】:

    在 .NET 5 winforms 应用程序中使用 uwp 蓝牙 API 时出现 TargetInvocationException

    恐怕在Windows 8.1系统下无法运行,请参考BluetoothLEAdvertisementWatcher文档,支持最低版本为Build 10240,在Windows 8.1系统下无法运行。

    【讨论】:

    • 那么有哪些可能的选项可以让它发挥作用?我的意思是如果我使用其他版本的 .net,比如 4.0?
    • 跟OS系统比较相关。 UWP api 仅适用于 windows 10 设备。
    • 我只希望 BLE 在 Windows 8.1 上使用 C# 代码工作,即使使用 winforms 也不可能?
    • 请使用纯桌面api或第三方库接近。
    • 问题是我找不到任何桌面的 ble api,所以我决定实现 uwp。如果您对桌面 api 有任何参考,请告诉我。谢谢
    猜你喜欢
    • 2021-03-16
    • 2016-07-10
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-10
    • 1970-01-01
    相关资源
    最近更新 更多