Bug 29140 - Cannot typecast to CastClass.IApplicationConnectionResult
Summary: Cannot typecast to CastClass.IApplicationConnectionResult
Status: CONFIRMED
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 4.20.0
Hardware: PC Mac OS
: High enhancement
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2015-04-16 03:14 UTC by Prashant Cholachagudda
Modified: 2017-07-03 18:01 UTC (History)
3 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 for Bug 29140 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:
Status:
CONFIRMED

Description Prashant Cholachagudda 2015-04-16 03:14:54 UTC
XA fails to cast the object received from IResultCallback.OnResult, while Android version give us the Generic version of `OnResult` method

C# sample:
class MyMediaRouterCallback
{
    private void Load()
    {
        IPendingResult result = Android.Gms.Cast.CastClass.CastApi.LaunchApplication(/*...*/);
        result.SetResultCallback(new ResultCallbackWrapper(this));
    }

     public void OnResult(Java.Lang.Object result) {
                //throws an exception
		CastClass.IApplicationConnectionResult  r = result as CastClass.IApplicationConnectionResult;
    }
}

Refer attached sample code.
Comment 2 Jonathan Pryor 2015-04-16 09:56:19 UTC
This is Bug #16604, which at the time was closed NOT_ON_ROADMAP, because I didn't want to enumerate all interfaces that a type implemented in preference to checking the base classes when determining the "best fit" wrapper type.

Theoretically, we could check interface types if the default base-class strategy fails. The problem with checking interfaces at all is that JNI doesn't expose a way to enumerate all the interfaces a class implements, which means to do so we would need to use JNI to invoke java.lang.Class.getInterfaces()...which is certainly possible.

In the meantime, use result.JavaCast<CastClass.IApplicationConnectionResult>() instead of the `as` operator.
Comment 3 Jon Douglas [MSFT] 2017-07-03 18:01:30 UTC
Marking CONFIRMED as to same behave described in https://bugzilla.xamarin.com/show_bug.cgi?id=29140#c1

Although https://bugzilla.xamarin.com/show_bug.cgi?id=29140#c2 describes a NOT_ON_ROADMAP scenario, I am leaving this as CONFIRMED until further movement.