Bug 59462 - Java.Util.NoSuchElementException couldn't cast to Java.Lang.Object
Summary: Java.Util.NoSuchElementException couldn't cast to Java.Lang.Object
Alias: None
Product: Android
Classification: Xamarin
Component: Android+BCL Integration ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Habersack
Depends on:
Reported: 2017-09-13 17:27 UTC by Tuyen Duc Vu
Modified: 2017-09-14 18:26 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 for Bug 59462 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Tuyen Duc Vu 2017-09-13 17:27:34 UTC
It should work, but actually

Java.Util.NoSuchElementException couldn't cast to Java.Lang.Object
Comment 1 Jon Douglas [MSFT] 2017-09-14 15:06:39 UTC
(In reply to Tuyen Duc Vu from comment #0)
> It should work, but actually
> ```
> Java.Util.NoSuchElementException couldn't cast to Java.Lang.Object
> ```

Hello and thank you for reporting a bug. If you can, please create a follow up comment with the follow details inside:

1. Steps to Reproduce or Reproducible Project
2. Actual Results
3. Expected Results
4. Version Information

You can find details on each of these items here:


Thank you in advance!
Comment 2 Tuyen Duc Vu 2017-09-14 15:23:04 UTC
1. Steps to Reproduce or Reproducible Project
- Create a new Java.Util.NoSuchElmentException
- Cast it to Java.Lang.Object
2. Actual Results
- Compiler error: Unable to cast
3. Expected Results
- No comiler error, cast successfully
4. Version Information
- Lastest
Comment 3 Jon Douglas [MSFT] 2017-09-14 18:26:18 UTC
I can CONFIRM this issue. I believe this might need the use of a JavaCast instead of a managed cast.

Can you try using a JavaCast? Here is an example:

>    Java.Util.NoSuchElementException ex = new Java.Util.NoSuchElementException();
>    var test = Android.Runtime.Extensions.JavaCast<Java.Lang.Object>(ex);

> The JavaCast() method allows performing such type conversions while bypassing the managed type system and instead relying upon the Android runtime system to perform the type checking.