AndroidX icon indicating copy to clipboard operation
AndroidX copied to clipboard

AndroidX.Credentials ICredentialManagerCallback wrong parameter types.

Open uwe-neuronation opened this issue 1 year ago • 2 comments

Android application type

Classic Xamarin.Android (MonoAndroid12.0, etc.), Android for .NET (net6.0-android, etc.)

Affected platform version

VS Mac 2022 17.6.9

Description

The interface ICredentialManagerCallback.cs OnError and OnResult use Java.Lang.Object parameter type. It should be

onResult(GetCredentialResponse result) and onError(GetCredentialException e)

Unfortunately, It is not possible cast. So, it's impossible to get a proper error message on the c# level.

Steps to Reproduce

ICredentialManager credentialManager = CredentialManager.Companion.Create(this.Context);
                CreatePublicKeyCredentialRequest createPublicKeyCredentialRequest = new CreatePublicKeyCredentialRequest(passkeyRequestVO.RequestJson);
                credentialManager.CreateCredentialAsync(this.Context, createPublicKeyCredentialRequest, new Android.OS.CancellationSignal(), this, this);
void ICredentialManagerCallback.OnError(Java.Lang.Object e){   System.Diagnostics.Debug.WriteLine("ICredentialManagerCallback.OnError: " + e);}
void ICredentialManagerCallback.OnResult(Java.Lang.Object result){    System.Diagnostics.Debug.WriteLine("ICredentialManagerCallback.OnResult");}

Bildschirmfoto 2024-03-05 um 11 57 22

Did you find any workaround?

nope

Relevant log output

No response

uwe-neuronation avatar Mar 05 '24 10:03 uwe-neuronation

You should be able to use JavaCast to cast to the correct type:

void ICredentialManagerCallback.OnResult (Java.Lang.Object result) 
{
    var r = result.JavaCast<GetCredentialResponse> ();
}

jpobst avatar Mar 06 '24 19:03 jpobst

You should be able to use JavaCast to cast to the correct type:

void ICredentialManagerCallback.OnResult (Java.Lang.Object result) 
{
    var r = result.JavaCast<GetCredentialResponse> ();
}

Thank you @jpobst that works. It's inconvenient, because I can't do type switch. Only works for the explicit exception type. In my case var r = e.JavaCast<CreatePublicKeyCredentialDomException>(); It throws an exception if the type does not match. So to cover all available exceptions types, it will be a big block of code.

Same interface OnResult works better, here it's Java.LangObjcte as well. But I can do a c# cast on the CreatePublicKeyCredentialResponse.

if (result is CreatePublicKeyCredentialResponse cpkcr) { ... }

Something is wrong with the exceptions themself.

uwe-neuronation avatar Mar 12 '24 11:03 uwe-neuronation