Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed to discover devices in windows11 #11

Closed
zerobikappa opened this issue Sep 10, 2024 · 5 comments
Closed

failed to discover devices in windows11 #11

zerobikappa opened this issue Sep 10, 2024 · 5 comments

Comments

@zerobikappa
Copy link

run bluetoothdevicepairing discover in powershell or cmd but the output only replied:

Failed: The parameter is incorrect.

The provided device ID is not a valid BluetoothDevice object.

May I know how can I get the device ID before discovering?

@PolarGoose
Copy link
Owner

Hello @zerobikappa,

Thank you for the report.
Could you please provide more details:

  • What is your OS?
  • Is it the full output that you see in the console?

@PolarGoose
Copy link
Owner

PolarGoose commented Sep 10, 2024

I think I understand what is going on:
I have found a similar issue: [CRSH] The provided device ID is not a valid BluetoothDevice object.
That was fixed in the following way: fix: fixed crash caused by unhandled exception in WindowsRT's device

I have fixed it and created a new version.
Could you please check if it works for you?
https://github.com/PolarGoose/BluetoothDevicePairing/releases/tag/v12.0

@zerobikappa
Copy link
Author

I tested with the new release. Now it can succeed to pair and connect.

I also found that in some situations, it may show different error message, which may be related to user spaces and permission:
(1) When I login with normal desktop, I can use BluetoothDevicePairing.exe in powershell to pair and connect:

PS> BluetoothDevicePairing.exe discover
-------------------------------------------------------------------------
|  |16:01:18:27:16:4d|         |T3                                      |
-------------------------------------------------------------------------

PS> BluetoothDevicePairing.exe pair-with-mac --mac 16:01:18:27:16:4d --type Bluetooth
Create Bluetooth device using Mac:'16:01:18:27:16:4d'
Request to pair device [name:'T3' mac:'16:01:18:27:16:4d' type:'Bluetooth' ConnectionStatus:'NotPaired']
Start pairing
Pairing mode: ConfirmOnly
Device has been successfully paired

(2) When I login via RDP, I could use GUI panel to pair and connect, but failed to use BluetoothDevicePairing.exe in powershell:

PS> BluetoothDevicePairing.exe discover
Start discovering devices for 10 seconds
Warning: failed to get information from the discovered device [T3; Bluetooth#Bluetooth00:a7:3c:19:05:ff-16:01:18:27:16:4d]. Error message: The type initializer for 'BluetoothDevicePairing.Bluetooth.Devices.AudioDevices.AudioDeviceEnumerator' threw an exception.

PS> BluetoothDevicePairing.exe pair-by-mac 16:01:18:27:16:4d --type Bluetooth
Create Bluetooth device using Mac:'16:01:18:27:16:4d'
Unexpected failure: System.TypeInitializationException: The type initializer for 'BluetoothDevicePairing.Bluetooth.Devices.AudioDevices.AudioDeviceEnumerator' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at BluetoothDevicePairing.Bluetooth.Devices.AudioDevices.AudioDeviceEnumerator.<EnumerateConnectors>d__5.MoveNext()
   at BluetoothDevicePairing.Bluetooth.Devices.AudioDevices.AudioDeviceEnumerator..cctor()
   --- End of inner exception stack trace ---
   at BluetoothDevicePairing.Bluetooth.Devices.AudioDevices.AudioDeviceEnumerator.GetAudioDevices(Guid containerId)
   at BluetoothDevicePairing.Bluetooth.Devices.Device..ctor(DeviceInformation info)
   at BluetoothDevicePairing.Bluetooth.Devices.BluetoothDevice.FromMac(DeviceMacAddress mac)
   at BluetoothDevicePairing.Commands.Utils.DeviceFinder.FindDevicesByMac(DeviceMacAddress mac, DeviceType deviceType)
   at BluetoothDevicePairing.Commands.PairDeviceByMac.Execute(PairDeviceByMacOptions opts)
   at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
   at Program.<<Main>$>g__ParseCommandLineAndExecuteActions|0_0(String[] args)
   at Program.<Main>$(String[] args)

(3) When I login via ssh(no GUI)(ssh will default to login with administrator privilege), I could discover device but failed to connect them:

PS> BluetoothDevicePairing.exe discover
Start discovering devices for 10 seconds
-------------------------------------------------------------------------
|  |16:01:18:27:16:4d|         |T3                                      |
-------------------------------------------------------------------------

PS> BluetoothDevicePairing.exe pair-by-mac --mac 16:01:18:27:16:4d --type Bluetooth
Create Bluetooth device using Mac:'16:01:18:27:16:4d'
Request to pair device [name:'T3' mac:'16:01:18:27:16:4d' type:'Bluetooth' ConnectionStatus:'NotPaired']
Start pairing
Failed: Failed to pair device. Status = Failed

@zerobikappa
Copy link
Author

my windows version:

Edition Windows 11 Pro
Version 23H2
Installed on ‎7/‎31/‎2023
OS build 22631.4169
Experience Windows Feature Experience Pack 1000.22700.1034.0

@PolarGoose
Copy link
Owner

PolarGoose commented Sep 18, 2024

@zerobikappa,

Thank you for sharing the details.
I have never considered using RDP or SSH. Now, I know how to reproduce the issue if necessary.
I think the problem is with the Windows.Devices.Enumeration API, which I use to work with Bluetooth.

When I login via RDP, I could use GUI panel to pair and connect

This GUI uses a different API

may be related to user spaces and permission

Yes, I think it is probably the cause.
Unfortunately, I'm not sure anything can be done about it unless I rewrite the code using WinApi.

As a workaround, you can try using Bluetooth Command Line Tools. I used them before I made BluetoothDevicePairing utility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants