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

MAUI macOS Terminating app due to uncaught exception 'System.ArgumentException', reason: 'idx (System.ArgumentException) #390

Open
npdwc opened this issue Jan 23, 2024 · 2 comments

Comments

@npdwc
Copy link

npdwc commented Jan 23, 2024

when I scan Bluetooth on macOS I get an exception
Looks like #262 but for macOS

*** Terminating app due to uncaught exception 'System.ArgumentException', reason: 'idx (System.ArgumentException)
   at Foundation.NSData.get_Item(IntPtr idx) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSData.cs:line 280
   at InTheHand.Bluetooth.BluetoothUuid.op_Implicit(CBUUID uuid)
   at InTheHand.Bluetooth.BluetoothAdvertisingEvent..ctor(BluetoothDevice device, NSDictionary advertisementData, NSNumber RSSI)
   at InTheHand.Bluetooth.Bluetooth._manager_DiscoveredPeripheral(Object sender, CBDiscoveredPeripheralEventArgs e)
   at CoreBluetooth.CBCentralManager._CBCentralManagerDelegate.DiscoveredPeripheral(CBCentralManager central, CBPeripheral peripheral, NSDictionary advertisementData, NSNumber RSSI) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/maccatalyst/generated-sources/CoreBluetooth/CBCentralManager.g.cs:line 557
'
@peterfoot
Copy link
Member

This is possibly because the CBUUID in question is 32 bit/4 byte and the conversion logic only currently supports 2 byte short ids or the full 16 byte uuids. I've added better error handling to return Guid.Empty if the length is not recognised, but will need to add 32 bit conversion too.

@peterfoot peterfoot added the iOS label Jan 28, 2024
@mksdevelop
Copy link

I'm getting this error on ios.
Maybe we should wrap some of the code in a try catch block? Or release a library update?

Unhandled Exception:
System.ArgumentException: idx
   at Foundation.NSData.get_Item(IntPtr idx) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSData.cs:line 280
   at InTheHand.Bluetooth.BluetoothUuid.op_Implicit(CBUUID uuid)
   at InTheHand.Bluetooth.BluetoothAdvertisingEvent..ctor(BluetoothDevice device, NSDictionary advertisementData, NSNumber RSSI)
   at InTheHand.Bluetooth.Bluetooth._manager_DiscoveredPeripheral(Object sender, CBDiscoveredPeripheralEventArgs e)
   at CoreBluetooth.CBCentralManager._CBCentralManagerDelegate.DiscoveredPeripheral(CBCentralManager central, CBPeripheral peripheral, NSDictionary advertisementData, NSNumber RSSI) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/CoreBluetooth/CBCentralManager.g.cs:line 569
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94
   at Project1.Program.Main(String[] args) in /Users/dev/Develop/Projects/Project1 Project1/Platforms/iOS/Program.cs:line 13
2024-02-29 11:46:20.258 Project1[1189:614552] Unhandled managed exception: idx (System.ArgumentException)
   at Foundation.NSData.get_Item(IntPtr idx) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSData.cs:line 280
   at InTheHand.Bluetooth.BluetoothUuid.op_Implicit(CBUUID uuid)
   at InTheHand.Bluetooth.BluetoothAdvertisingEvent..ctor(BluetoothDevice device, NSDictionary advertisementData, NSNumber RSSI)
   at InTheHand.Bluetooth.Bluetooth._manager_DiscoveredPeripheral(Object sender, CBDiscoveredPeripheralEventArgs e)
   at CoreBluetooth.CBCentralManager._CBCentralManagerDelegate.DiscoveredPeripheral(CBCentralManager central, CBPeripheral peripheral, NSDictionary advertisementData, NSNumber RSSI) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/CoreBluetooth/CBCentralManager.g.cs:line 569
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94
   at Project1.Program.Main(String[] args) in /Users/dev/Develop/Projects/Project1/Project1/Platforms/iOS/Program.cs:line 13

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

No branches or pull requests

3 participants