stride3d/stride · error · ArgumentException

The action must be FolderCreated or FolderDeleted when…

Error message

The action must be FolderCreated or FolderDeleted when using this constructor.

What it means

This EntityFolderOperation constructor overload is meant only for folder create/delete operations (no oldFolderName involved); passing FolderRenamed, which requires the other overload, throws ArgumentException.

Solutions

  1. Use Action.FolderCreated or Action.FolderDeleted with this constructor
  2. For renames use the overload that also accepts oldFolderName
  3. Centralize EntityFolderOperation creation in one factory validating the action before choosing the ctor

Example fix

// before
new EntityFolderOperation(asset, Action.FolderRenamed, path, ownerId); // throws
// after
new EntityFolderOperation(asset, Action.FolderRenamed, path, oldFolderName, ownerId);
Defensive patterns

Strategy: validation

Validate before calling

if (action != EntityFolderOperation.Action.FolderCreated && action != EntityFolderOperation.Action.FolderDeleted)
    throw new ArgumentException("Use FolderCreated/FolderDeleted ctor only", nameof(action));

Try / catch

try { op = new EntityFolderOperation(asset, action, path, ownerId); }
catch (ArgumentException ex) { log.Error(ex); op = null; }

Prevention

When it happens

Trigger: Constructing EntityFolderOperation with the 4-argument overload (asset, action, folderPath, ownerId) while action is FolderRenamed (or any value other than FolderCreated/FolderDeleted).

Common situations: Generic undo operation factories that always call the shorter ctor; refactor that added FolderRenamed handling but kept the old construction site; enum misuse in editor tooling.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/ViewModels/EntityFolderOperation.cs:48

            FolderDeleted,
            FolderRenamed,
        }

        public EntityFolderOperation([NotNull] EntityHierarchyViewModel asset, Action action, [NotNull] string folderPath, string oldFolderName, AbsoluteId ownerId)
            : this(action, folderPath, ownerId, asset.SafeArgument(nameof(asset)).Dirtiables)
        {
            if (action != Action.FolderRenamed)
                throw new ArgumentException(@"The action must be FolderRenamed when using this constructor.", nameof(action));

            this.asset = asset;
            this.oldFolderName = oldFolderName;
        }

        public EntityFolderOperation([NotNull] EntityHierarchyViewModel asset, Action action, [NotNull] string folderPath, AbsoluteId ownerId)
            : this(action, folderPath, ownerId, asset.SafeArgument(nameof(asset)).Dirtiables)
        {
            if (action != Action.FolderCreated && action != Action.FolderDeleted)
                throw new ArgumentException(@"The action must be FolderCreated or FolderDeleted when using this constructor.", nameof(action));

            this.asset = asset;
        }

        private EntityFolderOperation(Action action, [NotNull] string folderPath, AbsoluteId ownerId, IEnumerable<IDirtiable> dirtiables)
            : base(dirtiables)
        {
            this.action = action;
            this.folderPath = folderPath.Split(new[] { EntityFolderViewModel.FolderSeparator }, StringSplitOptions.RemoveEmptyEntries);
            this.ownerId = ownerId;
        }

        /// <inheritdoc/>
        protected override void FreezeContent()
        {
            asset = null;
        }

View on GitHub (pinned to 96fad776d2)