{"record":{"id":"8a41c60f7c626c24","repo":"stride3d/stride","slug":"parent-cannot-be-null-entityfolderviewmodel","errorCode":null,"errorMessage":"Parent cannot be null","messagePattern":"Parent cannot be null","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/ViewModels/EntityFolderViewModel.cs","lineNumber":55,"sourceCode":"\n        /// <summary>\n        /// The relative path from the owning entity (or root if the folder is at the top level).\n        /// </summary>\n        /// /// <remarks>Folder paths are case-insensitive.</remarks>\n        /// <seealso cref=\"Owner\"/>\n        [NotNull]\n        public string Path => CombinePath((Parent as EntityFolderViewModel)?.Path, Name);\n\n        /// <inheritdoc/>\n        /// <remarks>Folder names are case-insensitive.</remarks>\n        public override string Name { get { return name; } set { SetValue(() => CanUpdateName(value), () => UpdateName(value)); } }\n\n        /// <inheritdoc/>\n        public override EntityHierarchyElementViewModel Owner\n        {\n            get\n            {\n                if (Parent == null) throw new InvalidOperationException($\"{nameof(Parent)} cannot be null\");\n                return Parent.Owner;\n            }\n        }\n\n        /// <inheritdoc/>\n        public override IEnumerable<EntityViewModel> InnerSubEntities => Children.SelectMany(x => x.InnerSubEntities);\n\n        /// <inheritdoc/>\n        /// <remarks>\n        /// A folder has no index in the asset, because <see cref=\"EntityDesign.Folder\"/> holds a path only. Folders are\n        /// also sorted by name, and they always come before the entities. Therefore an item cannot be put before or\n        /// after a folder.\n        /// </remarks>\n        protected override bool SupportsInsertion => false;\n\n        [NotNull]\n        public ICommandBase RenameCommand { get; }\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/ViewModels/EntityFolderViewModel.cs#L37-L73","documentation":"EntityFolderViewModel.Owner walks up to the owning element via Parent; a folder view-model must always have a Parent. If Parent is null the view-model is not attached to the folder tree and an InvalidOperationException is thrown.","triggerScenarios":"Accessing Owner on an EntityFolderViewModel that was created but never added to a parent folder's Children collection, or whose parent was removed from the hierarchy.","commonSituations":"Creating folder view-models manually without attaching them; accessing Owner during teardown after the hierarchy was cleared; UI binding evaluating Owner on detached temp folders.","solutions":["Attach the folder to a parent (add to parent.Children) before reading Owner","Check the Owner property instead of Parent when the element may be detached, or null-check Parent at call sites","Avoid creating detached EntityFolderViewModel instances; use editor.CreateFolder","Defer bindings that read Owner until the folder tree is built"],"exampleFix":"// before\nvar owner = folderVm.Owner; // throws when detached\n// after\nvar owner = folderVm.Parent?.Owner;","handlingStrategy":"type-guard","validationCode":"if (folderVm.Parent == null) { /* attach to a parent or skip */ return; }","typeGuard":"static bool IsAttached(EntityFolderViewModel f) => f.Parent != null;","tryCatchPattern":"try { var owner = folderVm.Owner; }\ncatch (InvalidOperationException) { /* detached folder; skip */ }","preventionTips":["Always add folders via editor.CreateFolder so parenting is guaranteed","Null-check Parent before reading Owner in bindings","Detach-then-read patterns should capture Owner before removal"],"tags":["csharp","viewmodel","editor","null"],"backgroundTag":"null-argument","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"}