Bug 11317 - InvalidCastException in EAAccessoryManager
Summary: InvalidCastException in EAAccessoryManager
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.2.x
Hardware: Macintosh Other
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-03-21 08:42 UTC by Dean Cleaver
Modified: 2013-12-05 18:33 UTC (History)
2 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 Dean Cleaver 2013-03-21 08:42:17 UTC
System.InvalidCastException: Cannot cast from source type to destination type.
at MonoTouch.Foundation.NSArray.ArrayFromHandle[T] (IntPtr handle) [0x00000] in :0 
at MonoTouch.ExternalAccessory.EAAccessoryManager.get_ConnectedAccessories () [0x00000] in :0 
at KleverLogic.FlashValet.iPhone.Valet.LineaPro.get_IsConnected () [0x00000] in :0 

This is the code it's happening on:

EAAccessory[] accessories = EAAccessoryManager.SharedAccessoryManager.ConnectedAccessories;

This has happened twice in the last week on 2 different devices, but has worked on 100's of devices for the last year. Any ideas what could be causing it?

The device I am expecting to be attached is a LineaPro, but I don't believe that the device itself is causing the casting issue.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2013-03-21 19:44:18 UTC
It looks like the array returned by the call to the native connectedAccessories method contains elements which are not EAAccessory instances. Apple's documentation says the array will only contain EAAccessory instances, but the documentation might be wrong.

Is this reproducible or is it just logs from customers? Could it be that there are other devices attached?
Comment 2 Dean Cleaver 2013-03-21 20:00:22 UTC
I can't reproduce it, and I have only seen it "twice" but it happened 167 times in about 5 hours a few days ago on one device, and then about 50 times in an hour yesterday on a different device. Each time it happened I got an error logged containing that exact information.

Should I perhaps try change EAAccessory[] to object[] and then foreach (object and then do a convert to EAAccessory, and if that fails get it to email back what the object actually was?

We might be publishing a new version shortly so I can change the code as above if you think that's our best shot of detecting it? Like I said, this code has been working for a year, this version has bee out there for 4 months, and just suddenly this happens. One thing I can also do is look up the db and see what OS the guys were using on their devices at the time.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2013-03-22 05:33:08 UTC
Yes, I believe modifying how you get the connected accessories will be more robust (and hopefully it'll provide more information on how we can fix it).

Here is (untested) code that should do it: https://gist.github.com/rolfbjarne/e874c56ffcad962be653
Comment 4 PJ 2013-11-19 17:03:57 UTC
This bug has been in the NEEDINFO state with no changes for the last 90 days. Can we put this back into the NEW or CONFIRMED state, or are we still awaiting response?

If there is no change in the status of this bug over the next two weeks, this bug will be marked as NORESPONSE.
Comment 5 PJ 2013-12-05 18:33:57 UTC
This bug has not been changed from the NEEDINFO state since my previous comment, marking as RESOLVED NORESPONSE.

Please feel free to REOPEN this bug at any time if you are still experiencing the issue. Please add the requested information and set the bug back to the NEW (or CONFIRMED) state.