Getting Error: System.Exception: Could not get device interface detail. Error code: 122 when using HID.Net and USB.Net

Getting Error: System.Exception: Could not get device interface detail. Error code: 122 when using HID.Net and USB.Net

我有一个控制台应用程序 (.Net Core) 项目正在使用库中的 Hid.Net Library, where the end goal is to connect with my HID game controllers and read data from it, but as a starting point in understanding the library, I had written code to enumerate connected devices of the game controller I wanted to connect to. The code I had written was following the documentation。但是当我 运行 项目时,我得到了错误:

System.Exception: 无法获取设备接口详细信息。错误代码:122

这是我写的代码:

using System;
using System.Threading.Tasks;
using Device.Net;
using Hid.Net.Windows;
using Usb.Net.Windows;

namespace IOLibrary
{
    class Program
    {
        static void Main(string[] args)
        {
            CheckforDevices();

            Console.ReadLine();
        }

        static async Task CheckforDevices()
        {
            try
            {
                WindowsHidDeviceFactory.Register();
                WindowsUsbDeviceFactory.Register();

                var devices = await DeviceManager.Current.GetConnectedDeviceDefinitions(0x0079, 0x0006);
                foreach(var device in devices)
                {
                    Console.WriteLine(device.DeviceId);
                }

            }
            catch(Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
    }
}

我不明白我做错了什么,所以非常感谢任何解释或见解。

编辑:此错误已在当前 2.3 版本中修复。但是,如果您认为没有返回设备,仍然值得克隆存储库并单步执行代码。如果在尝试收集有关设备的信息的过程中出现问题,设备将不会返回

上一个答案: 这是已知的bug。有时,获取隐藏详细信息的调用不起作用,因此其余部分将失败。我实际上已经在这个提交 664978f5084a6113a2b9e9a0371d5c7d40f30731 中修复了这个问题,但我相信修复只在开发分支中。如果您签出该修订版,代码应该不会崩溃。我会尽快发布一个新的 NuGet 版本来解决这个问题。但是,您应该明白,如果 Hid.Net 无法获取设备的详细信息,则不会认为它已连接。