stride3d/stride · warning · InvalidOperationException

The DisabledCommand cannot be executed.

Error message

The DisabledCommand cannot be executed.

What it means

A sentinel error from DisabledCommand, an ICommand whose CanExecute always returns false and whose Execute/Execute() always throw this InvalidOperationException. It exists to represent a permanently disabled command in the editor UI (button bound to it stays disabled); this error fires only if code invokes Execute directly, bypassing the CanExecute check — e.g. a programmatic Execute on a command bound to a disabled action such as Reload.

Solutions

  1. Check IsEnabled/CanExecute before calling Execute
  2. Replace the DisabledCommand placeholder with a real command instance before wiring UI
  3. Do not invoke Execute directly from code when the command may be disabled

Example fix

// before
command.Execute(param); // command is DisabledCommand
// after
if (command.IsEnabled) command.Execute(param);
Defensive patterns

Strategy: validation

Validate before calling

if (!command.IsEnabled) return; // do not invoke

Type guard

bool IsInvokable(ICommand c) => c.IsEnabled && c is not DisabledCommand;

Try / catch

try { command.Execute(param); } catch (InvalidOperationException) { /* command permanently disabled */ }

Prevention

When it happens

Trigger: Calling Execute(object?) on DisabledCommand, e.g. from a Button click when CanExecute checks were bypassed or the bound command was swapped to the disabled placeholder.

Common situations: UI invoking a command whose CanExecute returned false due to missing RequerySuggested; using DisabledCommand.None as a placeholder and forgetting to swap it.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/aa524fd5e5db60a4. Report an issue: GitHub.

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation/Commands/DisabledCommand.cs:47

    }

    /// <inheritdoc/>
    public event EventHandler? CanExecuteChanged
    {
        add { }
        remove { }
    }

    /// <inheritdoc/>
    public bool CanExecute(object? parameter)
    {
        return false;
    }

    /// <inheritdoc/>
    public void Execute(object? parameter)
    {
        throw new InvalidOperationException($"The {nameof(DisabledCommand)} cannot be executed.");
    }

    /// <inheritdoc/>
    public void Execute()
    {
        throw new InvalidOperationException($"The {nameof(DisabledCommand)} cannot be executed.");
    }
}

View on GitHub (pinned to 96fad776d2)