Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AndroidX.Credentials ICredentialManagerCallback wrong parameter types. #856

Open
uwe-neuronation opened this issue Mar 5, 2024 · 2 comments

Comments

@uwe-neuronation
Copy link

uwe-neuronation commented Mar 5, 2024

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

@jpobst
Copy link
Contributor

jpobst commented Mar 6, 2024

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> ();
}

@uwe-neuronation
Copy link
Author

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.

@jpobst jpobst removed the packages label Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants