stride3d/stride · warning · InvalidOperationException

The IsEnabled property of the DisabledCommand cannot be…

Error message

The IsEnabled property of the DisabledCommand cannot be modified

What it means

DisabledCommand is an immutable always-disabled command. Its IsEnabled setter throws InvalidOperationException for any `true` value; only setting it to false is tolerated. The command can never be enabled.

Solutions

  1. Do not attempt to enable DisabledCommand; replace the instance with a real command implementation when action is needed
  2. Skip DisabledCommand instances in code that enables commands in bulk
  3. Use CommandBase with IsEnabled toggling if dynamic enablement is required

Example fix

// before
currentCommand.IsEnabled = true; // currentCommand is DisabledCommand
// after
if (currentCommand is not DisabledCommand) currentCommand.IsEnabled = true;
Defensive patterns

Strategy: validation

Validate before calling

if (command is DisabledCommand) return; // never attempt to enable

Type guard

bool IsEnabledMutable(ICommand c) => c is not DisabledCommand;

Try / catch

try { cmd.IsEnabled = true; } catch (InvalidOperationException) { /* DisabledCommand stays disabled */ }

Prevention

When it happens

Trigger: Assigning `disabledCommand.IsEnabled = true` directly, or a view-model/framework routine that bulk-enables commands including this singleton.

Common situations: Toggle-all-commands logic, re-enabling commands after an async operation, mistakenly treating DisabledCommand as a regular configurable command.

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/5bafdafad3a112bf. Report an issue: GitHub.

Appendix: source

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

public sealed class DisabledCommand : ICommandBase
{
    /// <summary>
    /// Gets a singleton instance of the <see cref="DisabledCommand"/>
    /// </summary>
    public static DisabledCommand Instance { get; } = new DisabledCommand();

    /// <summary>
    /// Initializes a new instance of the <see cref="DisabledCommand"/> class.
    /// </summary>
    private DisabledCommand()
    {
    }

    /// <inheritdoc/>
    public bool IsEnabled
    {
        get { return false; }
        set { if (!value) throw new InvalidOperationException($"The {nameof(IsEnabled)} property of the {nameof(DisabledCommand)} cannot be modified"); }
    }

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

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

    /// <inheritdoc/>
    public void Execute(object? parameter)
    {

View on GitHub (pinned to 96fad776d2)