OrchardCMS/OrchardCore · error · InvalidOperationException

Method " " does not support switch " ".

Error message

Method "{0}" does not support switch "{1}".

What it means

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.

Solutions

  1. Remove the unsupported switch from the command line.
  2. Check which switches the specific command method supports (via [OrchardSwitch] usages tied to that method) and use only those.
  3. If the method should accept the switch, decorate the property and make sure the method is included in the switch support list.

Example fix

// before
mycommand -reset -force   // 'force' not supported by mycommand
// after
mycommand -reset
Defensive patterns

Strategy: validation

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/cb0793d3d5dd8252. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Commands/DefaultCommandHandler.cs:182

    private void CheckMethodForSwitches(MethodInfo methodInfo, IDictionary<string, string> switches)
    {
        if (switches == null || switches.Count == 0)
        {
            return;
        }

        var supportedSwitches = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
        foreach (var switchesAttribute in methodInfo.GetCustomAttributes(typeof(OrchardSwitchesAttribute), false).Cast<OrchardSwitchesAttribute>())
        {
            supportedSwitches.UnionWith(switchesAttribute.Switches);
        }

        foreach (var commandSwitch in switches.Keys)
        {
            if (!supportedSwitches.Contains(commandSwitch))
            {
                throw new InvalidOperationException(S["Method \"{0}\" does not support switch \"{1}\".", methodInfo.Name, commandSwitch]);
            }
        }
    }

    private static object ConvertToType(Type type, string value)
    {
        if (type.IsEnum)
        {
            try
            {
                return Enum.Parse(type, value, true);
            }
            catch (ArgumentException)
            {
                return null;
            }
        }
        else

View on GitHub (pinned to 4306c0717f)