OrchardCMS/OrchardCore · error · InvalidOperationException
A property " " exists but is not decorated with
Error message
A property "{0}" exists but is not decorated with "{1}" What it means
A switch name matched a public property on the command handler, but that property lacks the required [OrchardSwitch] attribute, so it is not an eligible command switch. OrchardCore requires the attribute as an explicit opt-in; otherwise arbitrary public properties (like Context) could be set from the CLI. The throw happens right after the reflection lookup in SetSwitchValue.
Solutions
- Decorate the intended property with [OrchardSwitch] so it becomes a valid switch.
- Remove the offending switch from the command invocation if it was not meant to be settable.
- Verify the attribute is the Orchard-specific OrchardSwitchAttribute and not a similarly named attribute that does not match the typeof check.
Example fix
// before
public class MyCommand {
public bool Verbose { get; set; }
}
// after
public class MyCommand {
[OrchardSwitch]
public bool Verbose { get; set; }
} Defensive patterns
Strategy: validation
Validate before calling
var prop = handlerType.GetProperty(switchName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
if (prop?.GetCustomAttributes(typeof(OrchardSwitchAttribute), false).Length == 0)
throw new InvalidOperationException($"Property '{switchName}' is not a valid switch (missing [OrchardSwitch])"); Try / catch
try { await handler.ExecuteAsync(context); }
catch (InvalidOperationException ex) when (ex.Message.Contains("not decorated")) { logger.LogError("Switch targets a non-switch property; add [OrchardSwitch] or remove the switch"); } Prevention
- Every public switch property must carry [OrchardSwitch]
- Review new handler properties in code review to ensure they are either attributed or renamed to avoid collision with switch names
When it happens
Trigger: Calling SetSwitchValues with a switch whose key equals a plain public property name on the handler that was never decorated with [OrchardSwitchAttribute], e.g. `mycommand -Context foo`.
Common situations: Adding a new handler property but forgetting the attribute, or intentionally matching an infrastructure property by name from the command line.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Switch " " was not found
- Error converting value
- Command arguments " " don't match command definition
- Method " " does not support switch " ".
- Invalid return type used in a migration method.
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/207e57905a0b5c7e.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Commands/DefaultCommandHandler.cs:44
if (context.Switches != null && context.Switches.Count > 0)
{
foreach (var commandSwitch in context.Switches)
{
SetSwitchValue(commandSwitch);
}
}
}
private void SetSwitchValue(KeyValuePair<string, string> commandSwitch)
{
// Find the property.
var propertyInfo = GetType()
.GetProperty(commandSwitch.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase)
?? throw new InvalidOperationException(S["Switch \"{0}\" was not found", commandSwitch.Key]);
if (propertyInfo.GetCustomAttributes(typeof(OrchardSwitchAttribute), false).Length == 0)
{
throw new InvalidOperationException(S["A property \"{0}\" exists but is not decorated with \"{1}\"", commandSwitch.Key, nameof(OrchardSwitchAttribute)]);
}
// Set the value.
try
{
var value = ConvertToType(propertyInfo.PropertyType, commandSwitch.Value);
propertyInfo.SetValue(this, value, null /*index*/);
}
catch (Exception ex) when (!ex.IsFatal())
{
// TODO: (ngm) fix this message.
var message = S["Error converting value \"{0}\" to \"{1}\" for switch \"{2}\"",
commandSwitch.Value,
propertyInfo.PropertyType.FullName,
commandSwitch.Key];
throw new InvalidOperationException(message, ex);
}View on GitHub (pinned to 4306c0717f)