Bug 23793 - NSCFType data unrecognized selector sent to instance for Bluetooth LE
Summary: NSCFType data unrecognized selector sent to instance for Bluetooth LE
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 8.2.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Paola Villarreal
Depends on:
Reported: 2014-10-13 16:46 UTC by John Miller [MSFT]
Modified: 2014-10-27 15:49 UTC (History)
6 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description John Miller [MSFT] 2014-10-13 16:46:18 UTC

   The attached sample throws an exception and crashes with "[__NSCFType data] unrecognized selector sent to instance"

**Steps to Reproduce:**

   1. Download the sample here: http://developer.xamarin.com/content/BluetoothLEExplorer/BluetoothLEExplorer.zip
   2. Run on a device.
   3. Press Start to start the scan

**Actual Results:**

   Application crashes

**Expected Results:**

   No Crash

**Build Date & Platform:**

   XI 8.2
   iOS 8
Comment 1 Rolf Bjarne Kvinge [MSFT] 2014-10-14 04:45:03 UTC
I'm unable to reproduce this.

Can you attach the complete stack trace / crash report?
Comment 2 Ram Chandra 2014-10-14 06:27:20 UTC
I have checked this issue but I am unable to reproduce this issue.

Steps I followed:

1. Set iOS project as "Startup Project"
2. Run the attached folder on device
3. Tap the scan button.

When I tap the "Scan" button I observed that application is working fine without any error or crashes.

Screencast: http://www.screencast.com/t/9JpHJamYhuN

Please let me know if I am missing something ?

Environment Info:

Mac OS X 10.9.5
Xamarin Studio: 5.6.1 (build 5)
Mono 3.10.0 ((detached/633e444)
GTK+ 2.24.23 (Raleigh theme)
Xcode 6.0.1 (6528)
Xamarin.iOS : (Business Edition)
=== Build Information ===
Release ID: 506010005
Git revision: 4a603dc77610b9eff2a41582146c56b69a81ceba
Build date: 2014-10-09 11:07:06-04
Comment 3 John Miller [MSFT] 2014-10-14 11:59:39 UTC
In the sample, it crashes on this line:

> // ScannerHome.cs Line 144
> cell.DetailTextLabel.Text = "UUID: " + peripheral.UUID.ToString () + ", Signal Strength: " + peripheral.RSSI;

Full trace:

>[__NSCFType data]: unrecognized selector sent to instance 0x1469e6e0
>2014-10-14 08:58:04.680 XamarinRoboticsBluetoothLEExploreriOS[4268:1761271] Unhandled managed exception: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[__NSCFType data]: unrecognized selector sent to instance 0x1469e6e0 (MonoTouch.Foundation.MonoTouchException)
>  at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:IntPtr_objc_msgSend (intptr,intptr)
>  at MonoTouch.CoreBluetooth.CBUUID.get_Data () [0x00003] in /Developer/MonoTouch/Source/monotouch/src/build/compat/CoreBluetooth/CBUUID.g.cs:139 
>  at MonoTouch.CoreBluetooth.CBUUID.ToString (Boolean fullUuid) [0x00000] in /Developer/MonoTouch/Source/maccore/src/CoreBluetooth/CBUUID.cs:168 
>  at MonoTouch.CoreBluetooth.CBUUID.ToString () [0x00000] in /Developer/MonoTouch/Source/maccore/src/CoreBluetooth/CBUUID.cs:49 
>  at BluetoothLEExplorer.iOS.UI.Screens.Scanner.Home.ScannerHome+BleDeviceTableSource.GetCell (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00066] in /Users/johnmiller/Downloads/BluetoothLEExplorer/BluetoothLEExplorer.iOS/UI/Screens/Scanner/Home/ScannerHome.cs:144 
>  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
>  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62 
>  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:45 
>  at BluetoothLEExplorer.iOS.Application.Main (System.String[] args) [0x00008] in /Users/johnmiller/Downloads/BluetoothLEExplorer/BluetoothLEExplorer.iOS/Main.cs:16
Comment 4 Sebastien Pouliot 2014-10-14 18:00:13 UTC
That code is not hit without an BLE device. Seems all I got are BL devices around :| maybe I need to buy more gadgets...

OTOH I seem to have found 2 bugs (one compiler and another one related to null handling) in the test case.
Comment 5 Paola Villarreal 2014-10-15 11:07:19 UTC
Confirming bug using an Estimote iBeacon.
Comment 6 Paola Villarreal 2014-10-15 15:34:34 UTC
The issue is that the bridge between CFUUIDRef and CBUUID is not toll-free. The workaround for this is:

var uuid = CBUUID.FromCFUUID (peripheral.UUID.Handle);
cell.DetailTextLabel.Text = "UUID: " + uuid.ToString () + ", Signal Strength: " + peripheral.RSSI;

Comment 7 Dan Ardelean 2014-10-15 16:15:02 UTC
There is also a more obscure problem and I cannot understand where it is coming for. It regards the RSSI signal. In the sample you are trying if I am not mistaking is always 0 even after calling ReadRSSI method. Anyway in another application I am building with Xamarin for iOS at some point in time I am not receiving the RssiUpdated event from any device connected inside my application. All ReadRSSI methods don't trigger the event and the Device.RSSI is always 0. Here is the strange part: if I disable the bluetooth and enable it the RSSI part starts working again. Another thing if it helps when inside my application the RSSI part doesn't work if I launch other applications that can manage BLE devices like LightBlue I can actually see the RSSI values.

Any idea where is it coming from?
Comment 8 Paola Villarreal 2014-10-27 15:49:32 UTC
This (original) bug is being closed as it is fixed in maccore (c55b599254f46c083a27ff7376a397ecc876a74d). 

Regarding the ReadRSSI, could you please open another bug so we can triage it properly?

Thank you!