{"record":{"id":"bb1761d8ffea5694","repo":"RicoSuter/NSwag","slug":"the-command-commandname-could-not-be-found","errorCode":null,"errorMessage":"The command '\" + commandName + \"' could not be found.","messagePattern":"The command '\" \\+ commandName \\+ \"' could not be found\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/NSwag.Commands/NConsole/CommandLineProcessor.cs","lineNumber":192,"sourceCode":"                    {\n                        if (!usedArgs.Contains(arg))\n                        {\n                            unusedArgs.Add(arg);\n                        }\n                    }\n\n                    throw new UnusedArgumentException($\"Used arguments ({usedArgs.Count}) != Provided arguments ({commandArguments.Count()}) -> Check [{string.Join(\", \", unusedArgs)}]\");\n                }\n\n                var output = await command.RunAsync(this, _consoleHost);\n                return new CommandResult\n                {\n                    Command = command,\n                    Output = output\n                };\n            }\n            else\n                throw new InvalidOperationException(\"The command '\" + commandName + \"' could not be found.\");\n        }\n\n        /// <summary>Processes the command in the given command line arguments.</summary>\n        /// <param name=\"args\">The arguments.</param>\n        /// <param name=\"input\">The output from the previous command.</param>\n        /// <returns>The exeucuted command.</returns>\n        /// <exception cref=\"InvalidOperationException\">The command could not be found.</exception>\n        /// <exception cref=\"InvalidOperationException\">No dependency resolver available to create a command without default constructor.</exception>\n        public IList<CommandResult> Process(string[] args, object input = null)\n        {\n            return ProcessAsync(args, input).GetAwaiter().GetResult();\n        }\n\n        /// <summary>Processes the command in the given command line arguments.</summary>\n        /// <param name=\"args\">The arguments.</param>\n        /// <param name=\"input\">The output from the previous command.</param>\n        /// <returns>The exeucuted command.</returns>\n        public IList<CommandResult> ProcessWithExceptionHandling(string[] args, object input = null)","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/RicoSuter/NSwag/blob/63daf8fcc3a25151b62eb4b326a1e8ea048a0d41/src/NSwag.Commands/NConsole/CommandLineProcessor.cs#L174-L210","documentation":"CommandLineProcessor.ProcessSingleAsync looks up the command name given on the command line in the host's registered command table and, when no registration matches, throws this InvalidOperationException. It is NSwag's 'unknown subcommand' error: the CLI parsed arguments but the first token does not name any known command (e.g. 'openapi2jsonschema', 'asyncapi', 'help').","triggerScenarios":"ProcessSingleAsync is called with args whose first token does not match any registered IConsoleCommand name; typically the user typed a misspelled or non-existent command name, or the assembly containing the command type was not scanned/registered in the host.","commonSituations":"Typo on the command line (e.g. 'nswag openapi2csahrp'), running an old nswag binary that does not yet know a newer command, or custom command types not registered with the NConsole host.","solutions":["Check the command name spelling against 'nswag help' output and retry.","Update the NSwag CLI (dotnet tool update nswag or download latest) if using a recently added command.","If hosting programmatically, ensure the custom command type is registered with the CommandLineProcessor/host before processing."],"exampleFix":"// before\nnswag openapi2csahrp /input:swagger.json\n// after\nnswag openapi2csharpclient /input:swagger.json","handlingStrategy":"try-catch","validationCode":"var known = new[] { \"run\", \"openapi2csharpclient\", \"openapi2csharpcontroller\", \"openapi2typescriptclient\", \"openapi2jsonschema\", \"asyncapi\", \"version\", \"help\" };\nif (!known.Contains(args.FirstOrDefault(), StringComparer.OrdinalIgnoreCase))\n    throw new ArgumentException($\"Unknown NSwag command: {args.FirstOrDefault()}\");","typeGuard":null,"tryCatchPattern":"try { await processor.ProcessSingleAsync(args, null); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"could not be found\"))\n{ Console.Error.WriteLine($\"Unknown command. Run 'nswag help'. Details: {ex.Message}\"); }","preventionTips":["Run 'nswag help' to list valid commands before scripting.","Keep the NSwag tool updated to the version that supports your command.","Validate the first CLI token in wrapper scripts."],"tags":["cli","command-not-found","argument-parsing"],"backgroundTag":"command-not-found","analyzedSha":"63daf8fcc3a25151b62eb4b326a1e8ea048a0d41","analyzedAt":"2026-09-14T11:38:15.205Z","contentChangedAt":"2026-09-14T11:38:15.205Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}