stride3d/stride · error · InvalidOperationException

Simulated Keyboard does not exist

Error message

Simulated Keyboard does not exist

What it means

InputSourceSimulated.RemoveKeyboard requires the KeyboardSimulated instance to be present in the source's keyboards collection. Passing an untracked or already-removed keyboard throws InvalidOperationException.

Solutions

  1. Only remove keyboards created by this source
  2. Guard against double removal with bookkeeping or membership checks
  3. Use RemoveAllKeyboards for batch teardown
  4. After removal, drop references so the instance isn't passed again

Example fix

// before
source.RemoveKeyboard(keyboard);
source.RemoveKeyboard(keyboard); // throws
// after
if (keyboards.Contains(keyboard)) source.RemoveKeyboard(keyboard);
Defensive patterns

Strategy: validation

Validate before calling

if (createdKeyboards.Contains(keyboard)) source.RemoveKeyboard(keyboard);

Try / catch

try { source.RemoveKeyboard(keyboard); } catch (InvalidOperationException) { /* already removed */ }

Prevention

When it happens

Trigger: Calling RemoveKeyboard with a keyboard not created by this source's CreateKeyboard, or calling RemoveKeyboard twice on the same instance.

Common situations: Repeated test teardown; keyboards removed via RemoveAllKeyboards and then removed again individually; cross-source keyboard references.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Input/Simulated/InputSourceSimulated.cs:95

        public void RemoveAllMice()
        {
            foreach (var mouse in mice)
                UnregisterDevice(mouse);
            mice.Clear();
        }

        public KeyboardSimulated AddKeyboard()
        {
            var keyboard = new KeyboardSimulated(this);
            keyboards.Add(keyboard);
            RegisterDevice(keyboard);
            return keyboard;
        }

        public void RemoveKeyboard(KeyboardSimulated keyboard)
        {
            if (!keyboards.Contains(keyboard))
                throw new InvalidOperationException("Simulated Keyboard does not exist");
            UnregisterDevice(keyboard);
            keyboards.Remove(keyboard);
        }

        public void RemoveAllKeyboards()
        {
            foreach (var keyboard in keyboards)
                UnregisterDevice(keyboard);
            keyboards.Clear();
        }

        public PointerSimulated AddPointer()
        {
            var pointer = new PointerSimulated(this);
            pointers.Add(pointer);
            RegisterDevice(pointer);
            return pointer;
        }

View on GitHub (pinned to 96fad776d2)