{"record":{"id":"c8773c969bf24a5d","repo":"stride3d/stride","slug":"argumentoutofrangeexception-sceneviewmodel","errorCode":null,"errorMessage":"ArgumentOutOfRangeException","messagePattern":"ArgumentOutOfRangeException","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/ViewModel/SceneViewModel.cs","lineNumber":279,"sourceCode":"                            var index = e.NewStartingIndex;\n                            foreach (var scene in e.NewItems.Cast<SceneViewModel>())\n                            {\n                                // Note: this can happen after a cut/paste when the parent/child relationship is fixed-up.\n                                if (scene.Parent != this)\n                                {\n                                    scene.Parent?.Children.Remove(scene);\n                                    scene.Parent = this;\n                                }\n                                childrenNode.Add(scene.Id, new NodeIndex(index++));\n                            }\n                        }\n                        break;\n\n                    case NotifyCollectionChangedAction.Move:\n                    case NotifyCollectionChangedAction.Reset:\n                        throw new NotSupportedException();\n                    default:\n                        throw new ArgumentOutOfRangeException();\n                }\n            }\n            finally\n            {\n                updatingChildren = false;\n            }\n        }\n\n        private void ChildrenNodeItemChanged(object sender, ItemChangeEventArgs e)\n        {\n            if (updatingChildren)\n                return;\n\n            try\n            {\n                updatingChildren = true;\n                switch (e.ChangeType)\n                {","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/ViewModel/SceneViewModel.cs#L261-L297","documentation":"The default branch of the switch in SceneViewModel.ChildrenCollectionChanged throws ArgumentOutOfRangeException when the NotifyCollectionChangedAction is not one of the explicitly handled values. This is a defensive guard: the enum value received is outside the set {Replace, Add, Remove, Move, Reset}.","triggerScenarios":"CollectionChanged raised with an invalid or unrecognized NotifyCollectionChangedAction value (e.g. a cast of an arbitrary int into the enum), reaching the default: branch.","commonSituations":"Buggy custom collection implementations or unsafe casts producing undefined enum values; essentially never hit with a standard ObservableCollection, but possible with hand-rolled INotifyCollectionChanged sources.","solutions":["Fix the collection implementation or cast that produces an invalid NotifyCollectionChangedAction value.","Add a diagnostic log of e.Action in the default branch to identify the offending event source.","Handle the unknown action defensively (rebuild childrenNode from current state) instead of throwing."],"exampleFix":"// before\ncase NotifyCollectionChangedAction.Reset:\n    throw new NotSupportedException();\ndefault:\n    throw new ArgumentOutOfRangeException();\n// after\ncase NotifyCollectionChangedAction.Reset:\n    throw new NotSupportedException();\ndefault:\n    throw new InvalidOperationException($\"Unexpected NotifyCollectionChangedAction: {e.Action}\");","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(NotifyCollectionChangedAction), e.Action))\n    return; // invalid enum value, skip instead of crashing","typeGuard":"static bool IsValidAction(NotifyCollectionChangedAction a) =>\n    a is >= NotifyCollectionChangedAction.Add and <= NotifyCollectionChangedAction.Reset;","tryCatchPattern":"try { handler(sender, e); }\ncatch (ArgumentOutOfRangeException ex)\n{\n    logger.Warning($\"Unknown NotifyCollectionChangedAction from {sender}: {ex.Message}\");\n}","preventionTips":["Only subscribe to well-known INotifyCollectionChanged implementations.","Avoid int-to-enum casts when raising CollectionChanged events.","After Stride upgrades, re-check switch statements over enums for new members."],"tags":["csharp","argument-out-of-range","enum","stride-editor"],"backgroundTag":"argument-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}