Bug 23211 - NSInvalidArgumentException Thrown: unrecognized selector sent to instance when Camera Access Disabled
Summary: NSInvalidArgumentException Thrown: unrecognized selector sent to instance whe...
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-09-20 01:15 UTC by Cody Beyer (MSFT)
Modified: 2014-09-22 04:11 UTC (History)
4 users (show)

Tags:
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:
Status:
RESOLVED INVALID

Description Cody Beyer (MSFT) 2014-09-20 01:15:31 UTC
This is the exception we are getting:

Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[ALError UTF8String]: unrecognized selector sent to instance 0x16e55a50

The ALError object is defined in the binding project. However, it does not have a selector name UTF8String.

Here are the steps necessary to reproduce this issue.

1. Use an iPhone running iOS 8.
2. Run the iOS project (attached) in debug mode on your iPhone.
3. The first time you run the project on your phone, you should be prompted by the OS to allow access to microphone and camera. Allow access to both.
4. Stop the debugger and then run the project again. This time you should see a small self preview in the lower left corner of the screen.
5. Stop the debugger again.
6. Go to Settings -> Privacy -> Camera and turn off camera access for the Xamarin Demo app.
7. Go back to Xamarin Studio and run the project again.
8. You should get the error shown above.
Comment 2 Sadik Ali 2014-09-22 03:45:26 UTC
I have checked this issue and able to reproduce this. To reproduce this I have followed sample project and steps provided in above bug description.

In step 6. When, I turned off camera access for the Xamarin Demo app, and run application again getting following error:
"Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[ALError UTF8String]: unrecognized selector sent to instance 0x15ece300"

Screencast: http://www.screencast.com/t/BCs7ZHoJOZ

Environment Info:

=== Xamarin Studio ===

Version 5.4 (build 240)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
	Mono 3.8.0 ((no/45d0ba1)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 308000009

=== Xamarin.Android ===

Version: 4.16.0 (Enterprise Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		3.2    (API level 13)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		4.5    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Apple Developer Tools ===

Xcode 5.1 (5084)
Build 5B130a

=== Xamarin.iOS ===

Version: 8.0.0.62 (Enterprise Edition)
Hash: 8bd8158
Branch: 
Build date: 2014-09-18 09:12:55-0400

=== Xamarin.Mac ===

Version: 1.10.0.13 (Enterprise Edition)

=== Build Information ===

Release ID: 504000240
Git revision: 01786bc67c7024ec33d327ed27e4416d7a846f4e
Build date: 2014-09-17 10:58:48-04
Xamarin addins: 7cd7dfcd6b7b7b53281508954ec080f1cd153ad3

=== Operating System ===

Mac OS X 10.9.4
Darwin MacMini.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Comment 3 Rolf Bjarne Kvinge [MSFT] 2014-09-22 04:11:40 UTC
This looks like a bug in the AddLive library.

The problem is the onStartLocalVideo callback, when there's an error, AddLive passes the same value for both the first and second argument:

    public void onStartLocalVideo(ALError error, string videoSinkId)

from a native stack trace:

    frame #5: 0x001ce134 iOS`-[iOSViewController onStartLocalVideo:videoSinkId:](self=0x16e8dd90, _cmd=0x00827dae, p0=0x16e1fa80, p1=0x16e1fa80) + 100 at registrar.m:571

notice that p0 and p1 have the same value (it's an ALError instance). The problem arises when Xamarin.iOS tries to marshal the call to the managed method, the second argument is declared to be a string ('string videoSinkId'), and when converting from the native object (which is expected to be an NSString), Xamarin.iOS will call the 'UTF8String' selector on it (which breaks because the object isn't an NSString, it's an ALError).

One possible workaround would be to declare the second argument as an NSObject:

    public void onStartLocalVideo(ALError error, NSObject videoSinkId)

and in the method itself you can check if it's an ALError or an NSString:

    if (videoSinkId is NSString) { ... }
    else if (videoSinkId is ALError) { ... }