{"record":{"id":"d6c739d2d729e5f8","repo":"dotnet/aspnetcore","slug":"invocation-provides-d-argument-s-but-target-expe","errorCode":null,"errorMessage":"Invocation provides %d argument(s) but target expects %d.","messagePattern":"Invocation provides (.+?) argument\\(s\\) but target expects (.+?)\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/GsonHubProtocol.java","lineNumber":233,"sourceCode":"                    default:\n                        break;\n                }\n            }\n        } catch (IOException ex) {\n            throw new RuntimeException(\"Error reading JSON.\", ex);\n        }\n\n        return hubMessages;\n    }\n\n    @Override\n    public ByteBuffer writeMessage(HubMessage hubMessage) {\n        return ByteBuffer.wrap((gson.toJson(hubMessage) + RECORD_SEPARATOR).getBytes(StandardCharsets.UTF_8));\n    }\n\n    private ArrayList<Object> bindArguments(JsonArray argumentsToken, List<Type> paramTypes) {\n        if (argumentsToken.size() != paramTypes.size()) {\n            throw new RuntimeException(String.format(\"Invocation provides %d argument(s) but target expects %d.\", argumentsToken.size(), paramTypes.size()));\n        }\n\n        ArrayList<Object> arguments = null;\n        if (paramTypes.size() >= 1) {\n            arguments = new ArrayList<>();\n            for (int i = 0; i < paramTypes.size(); i++) {\n                arguments.add(gson.fromJson(argumentsToken.get(i), paramTypes.get(i)));\n            }\n        }\n\n        return arguments;\n    }\n\n    private ArrayList<Object> bindArguments(JsonReader reader, List<Type> paramTypes) throws IOException {\n        reader.beginArray();\n        int paramCount = paramTypes.size();\n        int argCount = 0;\n        ArrayList<Object> arguments = new ArrayList<>();","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/GsonHubProtocol.java#L215-L251","documentation":"GsonHubProtocol binds incoming invocation arguments to the parameter types declared when the handler was registered (hubConnection.on(target, action, Type...)). bindArguments requires the argument count from the server to exactly equal the registered parameter count; any mismatch throws.","triggerScenarios":"Server invokes a hub method with N arguments but the client registered on(\"Method\", action, types...) with M types where N != M. For example server sends 2 args but client registered a single-parameter handler.","commonSituations":"Server hub method signature changed (args added/removed) but the client was not updated; the on(...) call omitted a Type; or the server invokes with default/extra params the client does not expect.","solutions":["Update the client hubConnection.on(...) so the number of declared types matches the server method's parameters exactly.","If the server legitimately changed signature, release matching client/server versions together.","Double-check that every parameter has a corresponding Type argument in on(target, action, Type...).","Inspect the raw arguments array in the wire message to confirm the server-side count."],"exampleFix":"// before\nhubConnection.on(\"Send\", (String a) -> { ... }, String.class); // 1 type\n// server invokes \"Send\" with (String a, int b)\n\n// after\nhubConnection.on(\"Send\", (String a, Integer b) -> { ... }, String.class, Integer.class);","handlingStrategy":"validation","validationCode":"// before registering, confirm the handler arity matches the server contract\nvoid on(String target, Action action, Type... types) {\n  if (types.length != expectedServerParamCount(target)) {\n    throw new IllegalArgumentException(\"Parameter count mismatch for \" + target);\n  }\n  hubConnection.on(target, action, types);\n}","typeGuard":null,"tryCatchPattern":"try {\n  hubConnection.on(\"Send\", (String a, Integer b) -> {}, String.class, Integer.class);\n} catch (RuntimeException e) {\n  if (e.getMessage().contains(\"argument(s) but target expects\")) {\n    // adjust the declared Type... count to match the server\n  }\n}","preventionTips":["Keep client on(...) Type lists in sync with the server method signature.","Release client/server versions together when signatures change.","Double-check every parameter has a matching Type in on(target, action, Type...)."],"tags":["java","signalr","protocol","invocation","argument-binding","validation"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}