{"record":{"id":"cad5112e80d1d1a5","repo":"stride3d/stride","slug":"the-action-must-be-folderrenamed-when-using-this-constructor","errorCode":null,"errorMessage":"The action must be FolderRenamed when using this constructor.","messagePattern":"The action must be FolderRenamed when using this constructor\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/ViewModels/EntityFolderOperation.cs","lineNumber":38,"sourceCode":"    {\n        private readonly AbsoluteId ownerId;\n        private readonly string[] folderPath;\n        private Action action;\n        private string oldFolderName;\n        private EntityHierarchyViewModel asset;\n\n        public enum Action\n        {\n            FolderCreated,\n            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;","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/ViewModels/EntityFolderOperation.cs#L20-L56","documentation":"This EntityFolderOperation constructor overload is intended exclusively for folder rename operations; it stores an oldFolderName which only makes sense for renames. Passing any other Action value throws ArgumentException naming the action parameter.","triggerScenarios":"Constructing EntityFolderOperation with the 5-argument overload (asset, action, folderPath, oldFolderName, ownerId) while action is FolderCreated or FolderDeleted instead of FolderRenamed.","commonSituations":"Copy-pasted undo/redo operation construction; switching Action enums without switching constructor overload; generic operation builders that pick the wrong ctor for the action.","solutions":["Use Action.FolderRenamed with this constructor","For FolderCreated/FolderDeleted use the 4-argument overload without oldFolderName","Refactor operation creation to dispatch on the action enum and select the matching constructor"],"exampleFix":"// before\nnew EntityFolderOperation(asset, Action.FolderCreated, path, oldName, ownerId); // throws\n// after\nnew EntityFolderOperation(asset, Action.FolderRenamed, path, oldName, ownerId);","handlingStrategy":"validation","validationCode":"if (action != EntityFolderOperation.Action.FolderRenamed)\n    throw new ArgumentException(\"Use the FolderRenamed ctor only for renames\", nameof(action));","typeGuard":null,"tryCatchPattern":"try { op = new EntityFolderOperation(asset, action, path, oldName, ownerId); }\ncatch (ArgumentException ex) { log.Error(ex); op = null; }","preventionTips":["Use a factory method that maps Action enum to the correct ctor overload","Never pass oldFolderName for non-rename operations","Add enum-to-ctor unit tests for undo operations"],"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"}