Bug 16838 - Application 'Support4' throws exception "System.InvalidCastException" under Fragment->Tabs and Pager
Summary: Application 'Support4' throws exception "System.InvalidCastException" under F...
Alias: None
Product: Android
Classification: Xamarin
Component: Samples ()
Version: 4.12.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Ben O'Halloran
Depends on:
Reported: 2013-12-17 06:42 UTC by Prashant manu
Modified: 2014-06-30 10:35 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 Prashant manu 2013-12-17 06:42:13 UTC
Steps to reproduce this issue:
1. Open XS.
2. Open Support4 application.
3. Debug/Run the application.
4. Click Fragment option on device or emulator.
5. Click last option 'Tabs and pager'.

Actual Result: After clicking on 'Tabs and Pager' under Fragment, Application
gets crashed throwing exception "System.InvalidCastException".

Expected Result: Application should not crash after clicking on 'Tabs and
Pager' under Fragment.

Supplement information: 
Android Log: https://gist.github.com/saurabh360/92156a1643f4b0249727
Application Output: https://gist.github.com/saurabh360/1ab4e6a5532562c4c37a
ADB Logcat: https://gist.github.com/saurabh360/dd2c43ec0ad5fb038970

Environment details:
All Mac
XS 4.2.3(build 20)
Mono 3.2.6

Device Info:
Samsung S4
Version 4.3

Regression Status:
This sample was verified in Issue: https://bugzilla.xamarin.com/show_bug.cgi?id=7137
Comment 1 Peter Collins 2013-12-18 17:19:17 UTC
I was able to reproduce this *only* in Release configuration. I was unable to reproduce on Debug. I saw this on a v2.3.7 GenyMotion emu, as well as my v4.3 GS3.

Exception stack trace from logcat:
Comment 2 Atsushi Eno 2014-01-08 06:10:33 UTC
Weird, I cannot reproduce this with master (which should be almost the same as 4.11), x86 4.3 and 4.4 emulators. The activity launches and I could switch between two tabs.

Though I had to "fix build" before building Support4 ("SetHasOptionsMenu(true)" => "HasOptionsMenu = true" in four lines). They seems to have changed the API and the bound API has also changed. So - is it version dependent issue? I have 19.0.1 locally.
Comment 3 Oleg Demchenko 2014-01-14 14:08:30 UTC
Same story, can't reproduce this issue. The activity launches and I can switch
between two tabs in release and debug configuration.

Environment details:
OS X 10.9.1
Xamarin Studio 4.3.1 
Xamarin.Android 4.11.0
Phillips W732 with Android 4.3
Comment 4 Tajinder Singh 2014-03-26 05:58:34 UTC
I have checked this issue with the following builds:

XS 4.2.4(build 32)
X.Android 4.12.3-3

Sample Info:monodroid-samples-masterc 2f984b727b64117a9668012f547c9a30932d70c

App is throwing handled exception by clicking on 'Tabs and Pager' under Fragment in RELEASE mode while in DEBUG mode app is working fine.Below is the output for the same:
Build Output:https://gist.github.com/saurabh360/72e4d775927dbe3c6a5d

Even I am able to reproduce it with stable android 4.12.1-1 on RELEASE mode.

Note:I run the application on default settings not changed the target version etc. 

Device Info:
API 19 Emulator
S4 -V 4.3
S2 -V 2.3.3

Hence reopening this issue.
Comment 5 Peter Collins 2014-03-26 14:44:47 UTC
I am also still able to reproduce on _release_ mode only, as reported earlier.

Mono 3.4.0 ((no/704ca78)
XA 4.12-series / 7f0e3d3c
GS4 v4.3
Nexus 4 v4.4 (ART)
Comment 6 Ben O'Halloran 2014-06-30 10:35:01 UTC
The issue was setting the adapter. Replacing the normal C# cast to data.JavaCast<ICursor>() in Activities\LoaderCursorSupport.cs resolved the issue.
Commit: https://github.com/xamarin/monodroid-samples/commit/633fd9d075a283dcb5a32bbb2a951ad52fecaf80