{"record":{"id":"67423b486c1cd978","repo":"dotnet/aspnetcore","slug":"invocation-provides-d-argument-s-but-target-expe-67423b","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/messagepack/src/main/java/com/microsoft/signalr/messagepack/MessagePackHubProtocol.java","lineNumber":515,"sourceCode":"        return streams;\n    }\n\n    private void writeStreamIds(Collection<String> streamIds, MessagePacker packer) throws IOException {\n        if (streamIds != null) {\n            packer.packArrayHeader(streamIds.size());\n            for (String s: streamIds) {\n                packer.packString(s);\n            }\n        } else {\n            packer.packArrayHeader(0);\n        }\n    }\n\n    private Object[] bindArguments(MessageUnpacker unpacker, List<Type> paramTypes, ByteBuffer payload) throws IOException {\n        int argumentCount = unpacker.unpackArrayHeader();\n\n        if (paramTypes.size() != argumentCount) {\n            throw new RuntimeException(String.format(\"Invocation provides %d argument(s) but target expects %d.\", argumentCount, paramTypes.size()));\n        }\n\n        Object[] arguments = new Object[argumentCount];\n\n        for (int i = 0; i < argumentCount; i++) {\n            arguments[i] = readValue(unpacker, paramTypes.get(i), payload, true);\n        }\n\n        return arguments;\n    }\n\n    private Object readValue(MessageUnpacker unpacker, Type itemType, ByteBuffer payload, boolean outermostCall) throws IOException {\n        Class<?> itemClass = Utils.typeToClass(itemType);\n        MessageFormat messageFormat = unpacker.getNextFormat();\n        ValueType valueType = messageFormat.getValueType();\n        int length;\n        long readBytesStart;\n        Object item = null;","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/SignalR/clients/java/signalr/messagepack/src/main/java/com/microsoft/signalr/messagepack/MessagePackHubProtocol.java#L497-L533","documentation":"In bindArguments the count of arguments read off the wire is compared against the number of parameter types the InvocationBinder reported for the target method. A mismatch means the client registered a handler whose signature does not match what the server is sending for that hub method.","triggerScenarios":"The server invokes a hub method with N arguments but the client's binder (built from hubConnection.on(target, ...paramTypes)) declared M != N parameter types. The check at MessagePackHubProtocol.java:514-516 fails before any argument is decoded.","commonSituations":"Server hub method signature changed (params added/removed) without updating the client handler, wrong number of argument types passed to hubConnection.on(...), or a typo in the target method name binding to the wrong overload.","solutions":["Update the client hubConnection.on(...) registration so its parameter type list exactly matches the server hub method's current signature.","Verify the target method name string matches the server method exactly (case-sensitive).","Redeploy both client and server from the same shared contract/Interface assembly where possible."],"exampleFix":"// before - server now sends 2 args, client registered 1\nhubConnection.on(\"SendMessage\", (user) -> {...}, String.class);\n// after\nhubConnection.on(\"SendMessage\", (user, message) -> {...}, String.class, String.class);","handlingStrategy":"validation","validationCode":"// Mirror the server hub method's parameter list exactly when registering\nClass<?>[] serverParams = { String.class, String.class };\nif (serverParams.length != expectedArgCount) {\n    throw new IllegalStateException(\"Signature drift: \" + serverParams.length);\n}\nhubConnection.on(\"SendMessage\", (a, b) -> {}, serverParams);","typeGuard":"static boolean signaturesMatch(Class<?>[] registered, int serverArgCount) {\n    return registered != null && registered.length == serverArgCount;\n}","tryCatchPattern":"// bindArguments failure is wrapped by the protocol into InvocationBindingFailureMessage for\n// invocations (not thrown), so for invocations check the returned message type:\nList<HubMessage> msgs = protocol.parseMessages(buf, binder);\nfor (HubMessage m : msgs) {\n    if (m.getMessageType() == HubMessageType.INVOCATION_BINDING_FAILURE) {\n        // log and reconcile the signature mismatch\n    }\n}","preventionTips":["Share the hub interface/contract between client and server.","Update client handler registrations whenever the server method signature changes.","Use the exact, case-sensitive target method name."],"tags":["java","signalr","messagepack","binding","contract-mismatch"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}