Bug 29140 - Cannot typecast to CastClass.IApplicationConnectionResult
Summary: Cannot typecast to CastClass.IApplicationConnectionResult
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
Depends on:
Reported: 2015-04-16 03:14 UTC by Prashant Cholachagudda
Modified: 2017-07-03 18:01 UTC (History)
3 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:


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.

Note You need to log in before you can comment on or make changes to this bug.