{"record":{"id":"ae3bdfa01750c38b","repo":"stride3d/stride","slug":"the-action-must-be-foldercreated-or-folderdeleted-when-using","errorCode":null,"errorMessage":"The action must be FolderCreated or FolderDeleted when using this constructor.","messagePattern":"The action must be FolderCreated or FolderDeleted when using this constructor\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/ViewModels/EntityFolderOperation.cs","lineNumber":48,"sourceCode":"            FolderDeleted,\n            FolderRenamed,\n        }\n\n        public EntityFolderOperation([NotNull] EntityHierarchyViewModel asset, Action action, [NotNull] string folderPath, string oldFolderName, AbsoluteId ownerId)\n            : this(action, folderPath, ownerId, asset.SafeArgument(nameof(asset)).Dirtiables)\n        {\n            if (action != Action.FolderRenamed)\n                throw new ArgumentException(@\"The action must be FolderRenamed when using this constructor.\", nameof(action));\n\n            this.asset = asset;\n            this.oldFolderName = oldFolderName;\n        }\n\n        public EntityFolderOperation([NotNull] EntityHierarchyViewModel asset, Action action, [NotNull] string folderPath, AbsoluteId ownerId)\n            : this(action, folderPath, ownerId, asset.SafeArgument(nameof(asset)).Dirtiables)\n        {\n            if (action != Action.FolderCreated && action != Action.FolderDeleted)\n                throw new ArgumentException(@\"The action must be FolderCreated or FolderDeleted when using this constructor.\", nameof(action));\n\n            this.asset = asset;\n        }\n\n        private EntityFolderOperation(Action action, [NotNull] string folderPath, AbsoluteId ownerId, IEnumerable<IDirtiable> dirtiables)\n            : base(dirtiables)\n        {\n            this.action = action;\n            this.folderPath = folderPath.Split(new[] { EntityFolderViewModel.FolderSeparator }, StringSplitOptions.RemoveEmptyEntries);\n            this.ownerId = ownerId;\n        }\n\n        /// <inheritdoc/>\n        protected override void FreezeContent()\n        {\n            asset = null;\n        }\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/ViewModels/EntityFolderOperation.cs#L30-L66","documentation":"This EntityFolderOperation constructor overload is meant only for folder create/delete operations (no oldFolderName involved); passing FolderRenamed, which requires the other overload, throws ArgumentException.","triggerScenarios":"Constructing EntityFolderOperation with the 4-argument overload (asset, action, folderPath, ownerId) while action is FolderRenamed (or any value other than FolderCreated/FolderDeleted).","commonSituations":"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.","solutions":["Use Action.FolderCreated or Action.FolderDeleted with this constructor","For renames use the overload that also accepts oldFolderName","Centralize EntityFolderOperation creation in one factory validating the action before choosing the ctor"],"exampleFix":"// before\nnew EntityFolderOperation(asset, Action.FolderRenamed, path, ownerId); // throws\n// after\nnew EntityFolderOperation(asset, Action.FolderRenamed, path, oldFolderName, ownerId);","handlingStrategy":"validation","validationCode":"if (action != EntityFolderOperation.Action.FolderCreated && action != EntityFolderOperation.Action.FolderDeleted)\n    throw new ArgumentException(\"Use FolderCreated/FolderDeleted ctor only\", nameof(action));","typeGuard":null,"tryCatchPattern":"try { op = new EntityFolderOperation(asset, action, path, ownerId); }\ncatch (ArgumentException ex) { log.Error(ex); op = null; }","preventionTips":["Route renames to the oldFolderName ctor overload","Centralize operation creation in one validated factory","Test all enum values against the ctor matrix"],"tags":["csharp","undo-redo","editor","argument"],"backgroundTag":"invalid-argument-value","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"}