{"record":{"id":"5420785ef23fcaaa","repo":"stride3d/stride","slug":"unsupported-collection-operation","errorCode":null,"errorMessage":"Unsupported collection operation","messagePattern":"Unsupported collection operation","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Input/InputManager.cs","lineNumber":787,"sourceCode":"            // Set mouse position for first mouse device\n            if (HasMouse)\n            {\n                Mouse.SetPosition(normalizedPosition);\n            }\n        }\n\n        private void InputDevicesOnCollectionChanged(IInputSource source, TrackingCollectionChangedEventArgs e)\n        {\n            switch (e.Action)\n            {\n                case NotifyCollectionChangedAction.Add:\n                    OnInputDeviceAdded(source, (IInputDevice)e.Item);\n                    break;\n                case NotifyCollectionChangedAction.Remove:\n                    OnInputDeviceRemoved((IInputDevice)e.Item);\n                    break;\n                default:\n                    throw new InvalidOperationException(\"Unsupported collection operation\");\n            }\n        }\n\n        private void OnInputDeviceAdded(IInputSource source, IInputDevice device)\n        {\n            devices.Add(device);\n            if (!devicesById.TryAdd(device.Id, device))\n                throw new InvalidOperationException($\"Device with Id {device.Id}({device.Name}) already registered to {devicesById[device.Id].Name}\");\n\n            if (device is IKeyboardDevice)\n            {\n                RegisterKeyboard((IKeyboardDevice)device);\n                keyboards.Sort((l, r) => -l.Priority.CompareTo(r.Priority));\n            }\n            else if (device is IPointerDevice)\n            {\n                RegisterPointer((IPointerDevice)device);\n                pointers.Sort((l, r) => -l.Priority.CompareTo(r.Priority));","sourceCodeStart":769,"sourceCodeEnd":805,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Input/InputManager.cs#L769-L805","documentation":"InputDevicesOnCollectionChanged handles only Add and Remove actions on a device source's Devices collection; any other NotifyCollectionChangedAction reaches the default case and throws InvalidOperationException, since devices are produced/destroyed, not rearranged.","triggerScenarios":"An IInputSource raising CollectionChanged with Replace, Reset or Move on its Devices collection — e.g. a custom source that Clears or reorders its device list.","commonSituations":"Custom input sources calling devices.Clear() to unload; data-bound device lists being replaced wholesale; buggy third-party source implementations.","solutions":["Modify the source to Remove individual devices instead of Clear/Reset.","Reimplement the custom IInputSource so Devices only raises Add and Remove.","Remove the offending source via InputManager.Sources to tear down its devices."],"exampleFix":"// before\nDevices.Clear(); // triggers Reset -> throw\n// after\nforeach (var d in Devices.ToList()) Devices.Remove(d);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { /* source device updates */ }\ncatch (InvalidOperationException ex) when (ex.Message == \"Unsupported collection operation\")\n{ logger.Error(ex, \"Source raised unsupported Devices change; replacing source\"); }","preventionTips":["Custom sources must raise only Add/Remove on Devices.","Avoid Clear/Reset on device collections; remove items individually.","Test custom source hot-plug paths before shipping."],"tags":["input","devices","unsupported-collection-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}