dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.6k stars 10.06k forks source link

Android java client - RuntimeException: Invocation provides 1 argument(s) but target expects 0. #51189

Closed alexandersokol closed 1 year ago

alexandersokol commented 1 year ago

Is there an existing issue for this?

Describe the bug

When Android Java client receives a message, signalR library rises internal exception during parsing that causes the whole client to fail. For other clients on front-end and iOS app it works well without any errors. I tried newer versions of the library but it doesn't have any effect.

Tested on Android versions 11, 12, 13, 14

Expected Behavior

Sdk receives new message without exception

Steps To Reproduce

Raw message received:

{"type":1,"target":"ReceiveVisibilityStatus","arguments":[{"userId":96411,"callStatus":1}]}

Mapping object:

data class VisibilityStatus(val userId: Long, val callStatus: Int)

Subscription:

 hubConnection.on("ReceiveVisibilityStatus", {
            Timber.i("Visibility status changed: ${it.userId} ${it.callStatus}")
        }, VisibilityStatus::class.java)

Exceptions (if any)

Failed to bind arguments received in invocation 'null' of 'ReceiveVisibilityStatus'.
                             java.lang.RuntimeException: Invocation provides 1 argument(s) but target expects 0.
                                at com.microsoft.signalr.GsonHubProtocol.bindArguments(GsonHubProtocol.java:234)
                                at com.microsoft.signalr.GsonHubProtocol.parseMessages(GsonHubProtocol.java:108)
                                at com.microsoft.signalr.HubConnection.ReceiveLoop(HubConnection.java:469)
                                at com.microsoft.signalr.HubConnection.lambda$new$0$com-microsoft-signalr-HubConnection(HubConnection.java:168)
                                at com.microsoft.signalr.HubConnection$$ExternalSyntheticLambda47.invoke(Unknown Source:2)
                                at com.microsoft.signalr.WebSocketTransport.onReceive(WebSocketTransport.java:75)
                                at com.microsoft.signalr.WebSocketTransport.lambda$start$0$com-microsoft-signalr-WebSocketTransport(WebSocketTransport.java:52)
                                at com.microsoft.signalr.WebSocketTransport$$ExternalSyntheticLambda0.invoke(Unknown Source:2)
                                at com.microsoft.signalr.OkHttpWebSocketWrapper$SignalRWebSocketListener.onMessage(OkHttpWebSocketWrapper.java:95)
                                at okhttp3.internal.ws.RealWebSocket.onReadMessage(RealWebSocket.kt:333)
                                at okhttp3.internal.ws.WebSocketReader.readMessageFrame(WebSocketReader.kt:245)
                                at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.kt:106)
                                at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.kt:293)
                                at okhttp3.internal.ws.RealWebSocket$connect$1.onResponse(RealWebSocket.kt:195)
                                at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
                                at java.lang.Thread.run(Thread.java:1012)

.NET Version

No response

Anything else?

Back-end:

Microsoft.AspNetCore.SignalR (1.0.1) Microsoft.AspNetCore.SignalR.Common (3.1.3) Microsoft.AspNetCore.SignalR.Core (1.0.1) Microsoft.AspNetCore.SignalR.Protocols.Json (1.1.0) Microsoft.AspNetCore.SignalR.StackExchangeRedis (3.1.3)

Android:

com.microsoft.signalr:signalr:3.1.31 (also tested on 5.x, 6.x, 7.x, 8.x-preview with the same result)

BrennanConroy commented 1 year ago
 hubConnection.on("ReceiveVisibilityStatus", {
            Timber.i("Visibility status changed: ${it.userId} ${it.callStatus}")
        }, VisibilityStatus::class.java)

What is this syntax?

Where is it coming from? You aren't accepting any arguments in your lambda so the error makes complete sense. If you changed it to:

 hubConnection.on("ReceiveVisibilityStatus", (it) -> {
            Timber.i("Visibility status changed: ${it.userId} ${it.callStatus}")
        }, VisibilityStatus::class.java)

Then it would likely work.

alexandersokol commented 1 year ago

This is kotlin, it doesn't requires single lambda argument to be written, I mentioned that is Android app. Crash is inside signalR library, please check crash log.

BrennanConroy commented 1 year ago

An error log is not a crash. Is the client actually closing? I ran a small app that didn't have the correct number of arguments in the .on method and it just logs an error like expected, but the client keeps running.

Please provide a minimal repro app.

alexandersokol commented 1 year ago

I understand your logic. I was also thinking that the problem is in argument or target class, but other subscriptions works well the same way. I need some time to make a sample app.

alexandersokol commented 1 year ago

Issue was solved on client side. Seems it was an issue with incorrect subscription management across component's lifecycle changes.