{"record":{"id":"7492ab3aee51f1c4","repo":"OrchardCMS/OrchardCore","slug":"command-arguments-0-don-t-match-command-definition","errorCode":null,"errorMessage":"Command arguments \"{0}\" don't match command definition","messagePattern":"Command arguments \"(.+?)\" don't match command definition","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Commands/DefaultCommandHandler.cs","lineNumber":71,"sourceCode":"        catch (Exception ex) when (!ex.IsFatal())\n        {\n            // TODO: (ngm) fix this message.\n            var message = S[\"Error converting value \\\"{0}\\\" to \\\"{1}\\\" for switch \\\"{2}\\\"\",\n                commandSwitch.Value,\n                propertyInfo.PropertyType.FullName,\n                commandSwitch.Key];\n\n            throw new InvalidOperationException(message, ex);\n        }\n    }\n\n    private async Task InvokeAsync(CommandContext context)\n    {\n        CheckMethodForSwitches(context.CommandDescriptor.MethodInfo, context.Switches);\n\n        var arguments = (context.Arguments ?? []).ToArray();\n        var invokeParameters = GetInvokeParametersForMethod(context.CommandDescriptor.MethodInfo, arguments)\n            ?? throw new InvalidOperationException(S[\"Command arguments \\\"{0}\\\" don't match command definition\", string.Join(\" \", arguments)]);\n\n        Context = context;\n\n        if (context.CommandDescriptor.MethodInfo.ReturnType == typeof(Task<string>))\n        {\n            var taskResult = await (Task<string>)context.CommandDescriptor.MethodInfo.Invoke(this, invokeParameters);\n            await context.Output.WriteAsync(taskResult);\n            return;\n        }\n        else if (typeof(Task).IsAssignableFrom(context.CommandDescriptor.MethodInfo.ReturnType))\n        {\n            await (Task)context.CommandDescriptor.MethodInfo.Invoke(this, invokeParameters);\n            return;\n        }\n\n        var result = context.CommandDescriptor.MethodInfo.Invoke(this, invokeParameters);\n        if (result is string)\n        {","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Commands/DefaultCommandHandler.cs#L53-L89","documentation":"After resolving the command method, InvokeAsync builds the parameter list from the provided arguments; GetInvokeParametersForMethod returns null when the arguments cannot be matched to the method's parameter definition (wrong count or unbindable types). The handler then throws, indicating the CLI invocation does not fit the command's declared signature.","triggerScenarios":"Executing a command with more/fewer positional arguments than the handler method's parameters, or arguments that cannot be bound (e.g. missing default/optional parameters) in InvokeAsync called from ExecuteAsync.","commonSituations":"Command signature changed between versions while scripts still pass old argument orders, users omitting required arguments, or passing extra text after the command name.","solutions":["Compare your invocation against the command method's parameter list and pass the exact required positional arguments.","Run the command with no arguments or check help output to see the expected signature.","If the signature changed in an upgrade, update scripts/recipes to the new argument order.","If you own the command, consider optional parameters or clearer arity handling."],"exampleFix":"// before (expects: setup 'SiteName' 'admin' 'password')\nsetup 'My Site'\n// after\nsetup 'My Site' 'admin' 'Password1!'","handlingStrategy":"validation","validationCode":"var parameters = methodInfo.GetParameters();\nif (arguments.Length != parameters.Length)\n    throw new InvalidOperationException($\"Command '{methodInfo.Name}' expects {parameters.Length} arguments, got {arguments.Length}\");","typeGuard":null,"tryCatchPattern":"try { await handler.ExecuteAsync(context); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"don't match command definition\")) { logger.LogError(ex, \"Argument count/order mismatch for command\"); }","preventionTips":["Pin command signatures in scripts; re-check after upgrades","Document each command's argument list","Prefer named switches over positional args where possible"],"tags":["commands","argument-binding","cli"],"backgroundTag":"invalid-argument","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}