{"record":{"id":"cb0793d3d5dd8252","repo":"OrchardCMS/OrchardCore","slug":"method-0-does-not-support-switch-1","errorCode":null,"errorMessage":"Method \"{0}\" does not support switch \"{1}\".","messagePattern":"Method \"(.+?)\" does not support switch \"(.+?)\"\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Commands/DefaultCommandHandler.cs","lineNumber":182,"sourceCode":"\n    private void CheckMethodForSwitches(MethodInfo methodInfo, IDictionary<string, string> switches)\n    {\n        if (switches == null || switches.Count == 0)\n        {\n            return;\n        }\n\n        var supportedSwitches = new HashSet<string>(StringComparer.OrdinalIgnoreCase);\n        foreach (var switchesAttribute in methodInfo.GetCustomAttributes(typeof(OrchardSwitchesAttribute), false).Cast<OrchardSwitchesAttribute>())\n        {\n            supportedSwitches.UnionWith(switchesAttribute.Switches);\n        }\n\n        foreach (var commandSwitch in switches.Keys)\n        {\n            if (!supportedSwitches.Contains(commandSwitch))\n            {\n                throw new InvalidOperationException(S[\"Method \\\"{0}\\\" does not support switch \\\"{1}\\\".\", methodInfo.Name, commandSwitch]);\n            }\n        }\n    }\n\n    private static object ConvertToType(Type type, string value)\n    {\n        if (type.IsEnum)\n        {\n            try\n            {\n                return Enum.Parse(type, value, true);\n            }\n            catch (ArgumentException)\n            {\n                return null;\n            }\n        }\n        else","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Commands/DefaultCommandHandler.cs#L164-L200","documentation":"Before invoking, CheckMethodForSwitches collects the [OrchardSwitch]-decorated properties valid for the target method and rejects any switch the user passed that is not in that set. This is a per-method whitelist: a switch may exist on the handler class but still be unsupported for the specific command method being invoked.","triggerScenarios":"Invoking a command method with a switch defined on the handler class (or accepted by other methods) but not listed among the switches the invoked method supports, detected in the switches.Keys loop.","commonSituations":"Reusing switches across commands that do not all accept them, typo in a switch that coincidentally matches another command's switch, or copy-pasted command lines.","solutions":["Remove the unsupported switch from the command line.","Check which switches the specific command method supports (via [OrchardSwitch] usages tied to that method) and use only those.","If the method should accept the switch, decorate the property and make sure the method is included in the switch support list."],"exampleFix":"// before\nmycommand -reset -force   // 'force' not supported by mycommand\n// after\nmycommand -reset","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["commands","switches","cli"],"backgroundTag":"unsupported-operation","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}