{"record":{"id":"748a0d68769b2d8d","repo":"stride3d/stride","slug":"notsupportedexception-sceneviewmodel","errorCode":null,"errorMessage":"NotSupportedException","messagePattern":"NotSupportedException","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/ViewModel/SceneViewModel.cs","lineNumber":277,"sourceCode":"                        if (e.NewItems?.Count > 0)\n                        {\n                            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;","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/ViewModel/SceneViewModel.cs#L259-L295","documentation":"SceneViewModel.ChildrenCollectionChanged handles CollectionChanged notifications from the Children observable collection, syncing parent/child links and the underlying childrenNode list. It only supports Add, Remove and Replace actions; Move and Reset are treated as unsupported and throw NotSupportedException because the handler cannot incrementally reconstruct the parent-child state for them.","triggerScenarios":"Raising CollectionChanged with e.Action == Move (e.g. Children.Move(...)) or Reset (e.g. calling Children.Clear() or raising Reset) outside of an undo/redo transaction and while updatingChildren is false.","commonSituations":"Reordering child scenes in the scene editor by moving items in the collection, clearing the whole Children collection at once, or custom editor code that resets an ObservableCollection instead of adding/removing items individually.","solutions":["Replace Move/Reset operations with explicit Remove + Add calls on the Children collection at the correct indices.","Wrap bulk structural changes in an undo/redo transaction (UndoRedoService) or set the updatingChildren guard so the handler early-returns.","If Move/Reset support is needed, extend ChildrenCollectionChanged to rebuild childrenNode from the current Children state instead of throwing."],"exampleFix":"// before\nChildren.Clear(); // raises Reset -> NotSupportedException\n// after\nforeach (var child in Children.ToList())\n    Children.Remove(child); // raises Remove, which is handled","handlingStrategy":"try-catch","validationCode":"if (e.Action == NotifyCollectionChangedAction.Move || e.Action == NotifyCollectionChangedAction.Reset)\n    return; // or handle explicitly before mutating Children","typeGuard":"static bool IsSupported(e) => e is NotifyCollectionChangedEventArgs args &&\n    (args.Action == NotifyCollectionChangedAction.Add ||\n     args.Action == NotifyCollectionChangedAction.Remove ||\n     args.Action == NotifyCollectionChangedAction.Replace);","tryCatchPattern":"try\n{\n    Children.Move(oldIndex, newIndex);\n}\ncatch (NotSupportedException ex)\n{\n    // fall back to Remove+Add\n    var item = Children[oldIndex];\n    Children.RemoveAt(oldIndex);\n    Children.Insert(newIndex, item);\n}","preventionTips":["Never call Clear() or Move() on the Children collection; use Remove/Insert pairs.","Wrap bulk edits in undo/redo transactions so the change handler early-returns.","Keep item-level mutation of observable collections instead of resetting them."],"tags":["csharp","unsupported-operation","observable-collection","stride-editor"],"backgroundTag":"unsupported-operation","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"}