{"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/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/SignalR/clients/java/signalr/messagepack/src/main/java/com/microsoft/signalr/messagepack/MessagePackHubProtocol.java#L497-L533","documentation":"bindArguments compares the number of arguments in the incoming InvocationMessage against the number of parameter types the InvocationBinder returns for the target hub method. They must be equal; otherwise the invocation cannot be bound and a RuntimeException is thrown.","triggerScenarios":"Client invokes a server hub method with N args but the method is defined with M; server invokes a client method registered via .on(...) with a different arg count; a hub method signature was changed on one side only.","commonSituations":"Hub method signature refactored without updating clients; client-side .on(...) handler registered with the wrong parameter list; version skew between deployed server and client.","solutions":["Align the number of arguments sent with the hub method's parameter count.","For .on(...) client methods, register a callback whose arity matches what the server sends.","Rebuild and redeploy both sides after any hub signature change."],"exampleFix":"// before\n// server: public void Add(int a) {}\nhubConnection.send(\"Add\", 1, 2);\n\n// after\nhubConnection.send(\"Add\", 1);","handlingStrategy":"validation","validationCode":"// Java - confirm arity before invoking\njava.lang.reflect.Method m = hubMethods.get(target);\nif (m != null && m.getParameterCount() != args.length) {\n    throw new IllegalArgumentException(\"Argument count mismatch for \" + target);}\n","typeGuard":null,"tryCatchPattern":"// Java\nhubConnection.on(\"Method\", (a, b) -> {}, String.class, String.class);\ntry {\n    hubConnection.send(\"Method\", \"one\").blockingAwait();\n} catch (RuntimeException ex) {\n    if (ex.getMessage() != null && ex.getMessage().contains(\"argument(s) but target expects\")) {\n    }\n}","preventionTips":["Keep the number of arguments sent equal to the hub method's parameter count.","Register .on(...) callbacks with an arity matching what the server sends.","Redeploy both sides after any hub method signature change."],"tags":["signalr","messagepack","method-binding","signature"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}