stride3d/stride · error · NotSupportedException

Can't change the name of a UILibrary object.

Error message

Can't change the name of a UILibrary object.

What it means

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.

Solutions

  1. Rename the underlying asset instead (the asset's name, not the root view model's Name).
  2. Make the Name field read-only in the UI for the library root (disable the rename command / use IsEditable=false).
  3. Skip root nodes when batch-renaming hierarchy items.

Example fix

// before
libraryRootViewModel.Name = "MyLibrary";
// after
libraryRootViewModel.Asset.Asset.Name = "MyLibrary"; // rename the asset, not the root node
Defensive patterns

Strategy: type-guard

Validate before calling

bool canRename = !(node is UILibraryRootViewModel);

Type guard

static bool IsRenamable(IAssetNodeViewModel node) => !(node is UILibraryRootViewModel);

Try / catch

try { node.Name = newName; } catch (NotSupportedException ex) { /* rename the asset instead */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/b78d416c04e249fc. Report an issue: GitHub.

Appendix: source

Thrown at sources/editor/Stride.Assets.Presentation/AssetEditors/UILibraryEditor/ViewModels/UILibraryRootViewModel.cs:26

using Stride.Core.Extensions;
using Stride.Assets.Presentation.AssetEditors.UIEditor.ViewModels;
using Stride.Assets.Presentation.ViewModel;
using Stride.Assets.UI;
using Stride.UI;

namespace Stride.Assets.Presentation.AssetEditors.UILibraryEditor.ViewModels
{
    public sealed class UILibraryRootViewModel : UIRootViewModel
    {
        public UILibraryRootViewModel(UIEditorBaseViewModel editor, [NotNull] UILibraryViewModel asset, IEnumerable<UIElementDesign> rootElements)
            : base(editor, asset, rootElements)
        {
            NotifyGameSidePartAdded().Forget();
        }

        /// <inheritdoc />
        [NotNull]
        public override string Name { get => "UI Library"; set => throw new NotSupportedException("Can't change the name of a UILibrary object."); }

        /// <inheritdoc />
        public override void ReplaceRootElement(PanelViewModel sourcePanel, AssetCompositeHierarchyData<UIElementDesign, UIElement> hierarchy, Guid targetPanelId)
        {
            if (sourcePanel == null) throw new ArgumentNullException(nameof(sourcePanel));
            var index = Asset.Asset.Hierarchy.RootParts.IndexOf(x => x.Id == sourcePanel.Id.ObjectId);
            if (index < 0)
                throw new ArgumentException(@"The given source panel is not a root element of this asset.", nameof(sourcePanel));

            Asset.AssetHierarchyPropertyGraph.RemovePartFromAsset(sourcePanel.UIElementDesign);
            Asset.AssetHierarchyPropertyGraph.AddPartToAsset(hierarchy.Parts, hierarchy.Parts[targetPanelId], null, index);
        }

        /// <inheritdoc />
        protected override bool CanAddOrInsertChildren(IReadOnlyCollection<object> children, ref string message)
        {
            return true;
        }

View on GitHub (pinned to 96fad776d2)