{"record":{"id":"b78d416c04e249fc","repo":"stride3d/stride","slug":"can-t-change-the-name-of-a-uilibrary-object","errorCode":null,"errorMessage":"Can't change the name of a UILibrary object.","messagePattern":"Can't change the name of a UILibrary object\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/UILibraryEditor/ViewModels/UILibraryRootViewModel.cs","lineNumber":26,"sourceCode":"using Stride.Core.Extensions;\nusing Stride.Assets.Presentation.AssetEditors.UIEditor.ViewModels;\nusing Stride.Assets.Presentation.ViewModel;\nusing Stride.Assets.UI;\nusing Stride.UI;\n\nnamespace Stride.Assets.Presentation.AssetEditors.UILibraryEditor.ViewModels\n{\n    public sealed class UILibraryRootViewModel : UIRootViewModel\n    {\n        public UILibraryRootViewModel(UIEditorBaseViewModel editor, [NotNull] UILibraryViewModel asset, IEnumerable<UIElementDesign> rootElements)\n            : base(editor, asset, rootElements)\n        {\n            NotifyGameSidePartAdded().Forget();\n        }\n\n        /// <inheritdoc />\n        [NotNull]\n        public override string Name { get => \"UI Library\"; set => throw new NotSupportedException(\"Can't change the name of a UILibrary object.\"); }\n\n        /// <inheritdoc />\n        public override void ReplaceRootElement(PanelViewModel sourcePanel, AssetCompositeHierarchyData<UIElementDesign, UIElement> hierarchy, Guid targetPanelId)\n        {\n            if (sourcePanel == null) throw new ArgumentNullException(nameof(sourcePanel));\n            var index = Asset.Asset.Hierarchy.RootParts.IndexOf(x => x.Id == sourcePanel.Id.ObjectId);\n            if (index < 0)\n                throw new ArgumentException(@\"The given source panel is not a root element of this asset.\", nameof(sourcePanel));\n\n            Asset.AssetHierarchyPropertyGraph.RemovePartFromAsset(sourcePanel.UIElementDesign);\n            Asset.AssetHierarchyPropertyGraph.AddPartToAsset(hierarchy.Parts, hierarchy.Parts[targetPanelId], null, index);\n        }\n\n        /// <inheritdoc />\n        protected override bool CanAddOrInsertChildren(IReadOnlyCollection<object> children, ref string message)\n        {\n            return true;\n        }","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/UILibraryEditor/ViewModels/UILibraryRootViewModel.cs#L8-L44","documentation":"This error is declared in the documentation of UILibraryRootViewModel to indicate that the name of a UILibrary asset object is immutable through this view model. Attempting to rename a UILibrary via the UI library editor's view model raises this error because the asset's identity is fixed; name changes are not a supported operation on the root of a UI library.","triggerScenarios":"Assigning to Name on the root view model of a UI library editor, e.g. binding a name text box TwoWay to the root node's Name, or calling rename on the library root in the scene/editor tree.","commonSituations":"Renaming the library via the editor tree's rename command; a generic property grid that exposes Name as editable for all hierarchy nodes; automated tests setting Name on every node.","solutions":["Rename the underlying asset instead (the asset's name, not the root view model's Name).","Make the Name field read-only in the UI for the library root (disable the rename command / use IsEditable=false).","Skip root nodes when batch-renaming hierarchy items."],"exampleFix":"// before\nlibraryRootViewModel.Name = \"MyLibrary\";\n// after\nlibraryRootViewModel.Asset.Asset.Name = \"MyLibrary\"; // rename the asset, not the root node","handlingStrategy":"type-guard","validationCode":"bool canRename = !(node is UILibraryRootViewModel);","typeGuard":"static bool IsRenamable(IAssetNodeViewModel node) => !(node is UILibraryRootViewModel);","tryCatchPattern":"try { node.Name = newName; } catch (NotSupportedException ex) { /* rename the asset instead */ }","preventionTips":["Disable rename UI for library root nodes.","Rename the asset object, never the root view model's Name.","In bulk rename scripts, skip root view models."],"tags":["stride","ui-library","readonly-property","notsupportedexception"],"backgroundTag":"operation-not-supported","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"}