{"record":{"id":"9dddd662aa1e31fa","repo":"stride3d/stride","slug":"the-folder-being-deleted-is-not-empty","errorCode":null,"errorMessage":"The folder being deleted is not empty.","messagePattern":"The folder being deleted is not empty\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/ViewModels/EntityFolderViewModel.cs","lineNumber":132,"sourceCode":"            var indexInFolder = 0;\n            var i = 0;\n            foreach (var entity in entityCollection)\n            {\n                if (i++ == indexInEntity)\n                    break;\n\n                if (string.Equals(entity.Folder, Path, FolderCase))\n                    ++indexInFolder;\n            }\n            return indexInFolder;\n        }\n\n        /// <summary>\n        /// Deletes this folder. The folder must not contain any entity before being deleted.\n        /// </summary>\n        public void Delete()\n        {\n            if (InnerSubEntities.Any()) throw new InvalidOperationException(\"The folder being deleted is not empty.\");\n            var path = Path;\n            var ownerId = Owner.Id;\n            if (Parent == null) throw new InvalidOperationException($\"{nameof(Parent)} cannot be null\");\n            Parent.Folders.Remove(this);\n            if (!Editor.UndoRedoService.UndoRedoInProgress)\n            {\n                var operation = new EntityFolderOperation(Asset, EntityFolderOperation.Action.FolderDeleted, path, ownerId);\n                Editor.UndoRedoService.PushOperation(operation);\n            }\n        }\n\n        /// <inheritdoc />\n        public override GraphNodePath GetNodePath()\n        {\n            return Owner.GetNodePath();\n        }\n\n        private bool CanUpdateName([CanBeNull] string newName)","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/ViewModels/EntityFolderViewModel.cs#L114-L150","documentation":"EntityFolderViewModel.Delete() refuses to delete a folder that still contains entities (directly or in subfolders, via InnerSubEntities). Stride requires folders to be emptied first so the undo/redo operation only has to record a simple folder deletion. Thrown as InvalidOperationException before any hierarchy mutation happens.","triggerScenarios":"Calling Delete() on an EntityFolderViewModel whose InnerSubEntities collection is non-empty, e.g. deleting a folder that has entities placed in it or in any nested subfolder.","commonSituations":"User-facing 'delete folder' command invoked on a populated folder; scripted batch cleanup of an entity hierarchy that forgot to move or delete child entities first.","solutions":["Move or delete all entities inside the folder (and subfolders) before calling Delete()","Check InnerSubEntities.Any() before calling Delete and inform the user the folder must be empty","Recursively delete subfolders after emptying them, then delete the parent folder"],"exampleFix":"// before\nfolder.Delete(); // throws if not empty\n// after\nif (!folder.InnerSubEntities.Any())\n    folder.Delete();\nelse\n    // move/delete entities first or notify the user","handlingStrategy":"validation","validationCode":"if (folder.InnerSubEntities.Any()) throw new InvalidOperationException(\"Move or delete entities before deleting this folder.\");\nfolder.Delete();","typeGuard":null,"tryCatchPattern":"try { folder.Delete(); }\ncatch (InvalidOperationException) { /* prompt user to empty the folder */ }","preventionTips":["Always check InnerSubEntities.Any() before Delete","Recursively empty subfolders first","Surface the empty-folder requirement in UI before enabling the delete command"],"tags":["csharp","stride","viewmodel","invalid-operation"],"backgroundTag":"invalid-state-transition","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"}