stride3d/stride · error · InvalidOperationException

Parent cannot be null

Error message

Parent cannot be null

What it means

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.

Solutions

  1. Attach the folder to a parent (add to parent.Children) before reading Owner
  2. Check the Owner property instead of Parent when the element may be detached, or null-check Parent at call sites
  3. Avoid creating detached EntityFolderViewModel instances; use editor.CreateFolder
  4. Defer bindings that read Owner until the folder tree is built

Example fix

// before
var owner = folderVm.Owner; // throws when detached
// after
var owner = folderVm.Parent?.Owner;
Defensive patterns

Strategy: type-guard

Validate before calling

if (folderVm.Parent == null) { /* attach to a parent or skip */ return; }

Type guard

static bool IsAttached(EntityFolderViewModel f) => f.Parent != null;

Try / catch

try { var owner = folderVm.Owner; }
catch (InvalidOperationException) { /* detached folder; skip */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/8a41c60f7c626c24. Report an issue: GitHub.

Appendix: source

Thrown at sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/ViewModels/EntityFolderViewModel.cs:55

        /// <summary>
        /// The relative path from the owning entity (or root if the folder is at the top level).
        /// </summary>
        /// /// <remarks>Folder paths are case-insensitive.</remarks>
        /// <seealso cref="Owner"/>
        [NotNull]
        public string Path => CombinePath((Parent as EntityFolderViewModel)?.Path, Name);

        /// <inheritdoc/>
        /// <remarks>Folder names are case-insensitive.</remarks>
        public override string Name { get { return name; } set { SetValue(() => CanUpdateName(value), () => UpdateName(value)); } }

        /// <inheritdoc/>
        public override EntityHierarchyElementViewModel Owner
        {
            get
            {
                if (Parent == null) throw new InvalidOperationException($"{nameof(Parent)} cannot be null");
                return Parent.Owner;
            }
        }

        /// <inheritdoc/>
        public override IEnumerable<EntityViewModel> InnerSubEntities => Children.SelectMany(x => x.InnerSubEntities);

        /// <inheritdoc/>
        /// <remarks>
        /// A folder has no index in the asset, because <see cref="EntityDesign.Folder"/> holds a path only. Folders are
        /// also sorted by name, and they always come before the entities. Therefore an item cannot be put before or
        /// after a folder.
        /// </remarks>
        protected override bool SupportsInsertion => false;

        [NotNull]
        public ICommandBase RenameCommand { get; }

View on GitHub (pinned to 96fad776d2)