{"record":{"id":"63ec70833f8cc95b","repo":"stride3d/stride","slug":"invalidoperationexception-sceneviewmodel","errorCode":null,"errorMessage":"InvalidOperationException","messagePattern":"InvalidOperationException","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/ViewModel/SceneViewModel.cs","lineNumber":322,"sourceCode":"                        {\n                            childId = (AssetId)e.OldValue;\n                            childScene = (SceneViewModel)Session.GetAssetById(childId);\n                            childScene.Parent = null;\n                            Children.Remove(childScene);\n                        }\n                        if (e.NewValue != null)\n                        {\n                            childId = (AssetId)e.NewValue;\n                            childScene = (SceneViewModel)Session.GetAssetById(childId);\n                            childScene.Parent?.Children.Remove(childScene);\n                            childScene.Parent = this;\n                            Children.Insert(e.Index.Int, childScene);\n                        }\n                        break;\n\n                    case ContentChangeType.None:\n                    case ContentChangeType.ValueChange:\n                        throw new InvalidOperationException();\n                    default:\n                        throw new ArgumentOutOfRangeException();\n                }\n            }\n            finally\n            {\n                updatingChildren = false;\n            }\n        }\n\n        private void ParentNodeValueChanged(object sender, MemberNodeChangeEventArgs e)\n        {\n            if (updatingParent)\n                return;\n\n            try\n            {\n                updatingParent = true;","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/ViewModel/SceneViewModel.cs#L304-L340","documentation":"SceneViewModel.ChildrenNodeItemChanged reacts to changes of the underlying childrenNode identifier collection. Only CollectionUpdate, CollectionAdd and CollectionRemove change types are supported; ContentChangeType.None and ContentChangeType.ValueChange indicate a change type that should never occur on a collection node, so the handler throws InvalidOperationException to flag a broken internal invariant.","triggerScenarios":"A ValueChange or None event raised on the childrenNode member node (e.g. the whole childrenNode property being replaced rather than mutated as a collection) while updatingChildren is false.","commonSituations":"Undo/redo or serialization code assigning a new list to the childrenNode property instead of adding/removing entries, triggering a value-level change event on a collection that only supports item-level events.","solutions":["Mutate childrenNode through its collection API (Add/Remove/Insert) instead of reassigning the property reference.","If reassignment is unavoidable, guard the change with updatingChildren (or an undo/redo transaction) so the handler skips it.","Extend ChildrenNodeItemChanged to handle ValueChange by rebuilding Children from the new child-id list."],"exampleFix":"// before\nscene.childrenNode = newChildIds; // raises ValueChange -> InvalidOperationException\n// after\nscene.childrenNode.Clear();\nforeach (var id in newChildIds)\n    scene.childrenNode.Add(id);","handlingStrategy":"try-catch","validationCode":"if (e.ChangeType is ContentChangeType.None or ContentChangeType.ValueChange)\n    return; // not a collection-level change; handle or skip","typeGuard":"static bool IsCollectionChange(ContentChangeType t) =>\n    t is ContentChangeType.CollectionUpdate or ContentChangeType.CollectionAdd or ContentChangeType.CollectionRemove;","tryCatchPattern":"try\n{\n    MutateChildrenViaCollectionApi();\n}\ncatch (InvalidOperationException)\n{\n    // property was reassigned instead of mutated; rebuild Children from childrenNode\n    RebuildChildrenFromIds();\n}","preventionTips":["Mutate childrenNode via Add/Remove/Insert, never reassign the property reference.","Keep structural child edits inside undo/redo transactions.","Guard with the updatingChildren flag when performing programmatic repairs."],"tags":["csharp","invalid-operation","stride-editor","event-handling"],"backgroundTag":"invalid-state-transition","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"}