{"record":{"id":"4a5369b9702701eb","repo":"stride3d/stride","slug":"can-t-change-the-parent-of-this-folder","errorCode":null,"errorMessage":"Can't change the parent of this folder","messagePattern":"Can't change the parent of this folder","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Core.Assets.Editor/ViewModel/DirectoryBaseViewModel.cs","lineNumber":167,"sourceCode":"                var directoryNames = path.Split(Separator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);\n                result = directoryNames.Aggregate(result, (current, next) => current.SubDirectories.FirstOrDefault(x => string.Equals(next, x.Name, StringComparison.InvariantCultureIgnoreCase)) ?? new DirectoryViewModel(next, current, canUndoRedoCreation));\n            }\n            return result;\n        }\n\n        public abstract bool CanDelete(out string error);\n\n        public abstract void Delete();\n\n        /// <summary>\n        /// Set the parent of this directory and properly update <see cref=\"SubDirectories\"/> collection of the previous and the new parent.\n        /// </summary>\n        /// <remarks>Should be invoked only by the setter of <see cref=\"Parent\"/>.</remarks>\n        /// <param name=\"oldParent\">The old parent of this directory.</param>\n        /// <param name=\"newParent\">The nwe parent of this directory.</param>\n        protected void SetParent(DirectoryBaseViewModel oldParent, DirectoryBaseViewModel newParent)\n        {\n            if (this is not DirectoryViewModel directory) throw new InvalidOperationException(\"Can't change the parent of this folder\");\n\n            Dispatcher.Invoke(() =>\n            {\n                oldParent?.subDirectories.Remove(directory);\n\n                if (newParent != null)\n                {\n                    newParent.subDirectories.Add(directory);\n                    UpdateAssetUrls();\n                }\n            });\n        }\n\n        protected void UpdateAssetUrls()\n        {\n            var hierarchy = new List<DirectoryBaseViewModel>();\n            GetDirectoryHierarchy(hierarchy);\n","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Core.Assets.Editor/ViewModel/DirectoryBaseViewModel.cs#L149-L185","documentation":"DirectoryBaseViewModel.SetParent is the single hook used by the Parent property setter to reparent a directory node in the asset editor's folder tree. It is only valid for concrete DirectoryViewModel instances; other subclasses (e.g. MountPointViewModel) have fixed or null parents, so the method throws InvalidOperationException to refuse the operation.","triggerScenarios":"Calling SetParent on a DirectoryBaseViewModel subclass that is not a DirectoryViewModel — typically by assigning the Parent property of a MountPointViewModel or another non-DirectoryViewModel node instead of a real folder.","commonSituations":"Custom editor plugins or tree-manipulation code that walks the directory hierarchy generically and tries to move/attach any DirectoryBaseViewModel node, accidentally targeting a mount point or other special node.","solutions":["Only invoke SetParent (or set Parent) on instances of DirectoryViewModel","Guard with a type check before reparenting","Use the mount point's dedicated APIs instead of reparenting it"],"exampleFix":"// before\nnode.Parent = newParent;\n// after\nif (node is DirectoryViewModel dir) { dir.Parent = newParent; }","handlingStrategy":"type-guard","validationCode":"if (node is not DirectoryViewModel) throw new ArgumentException(\"Only DirectoryViewModel can be reparented\");","typeGuard":"bool CanReparent(DirectoryBaseViewModel n) => n is DirectoryViewModel;","tryCatchPattern":"try { node.Parent = newParent; } catch (InvalidOperationException) { /* node is not a real directory */ }","preventionTips":["Type-check DirectoryViewModel before reparenting","Never set Parent on mount points","Centralize tree mutations in one guarded helper"],"tags":["wpf","viewmodel","invalid-operation"],"backgroundTag":"unsupported-operation","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"}