{"record":{"id":"fc8252fcabf4b55a","repo":"stride3d/stride","slug":"the-given-source-panel-is-not-a-root-element-of-this-asset","errorCode":null,"errorMessage":"The given source panel is not a root element of this asset.","messagePattern":"The given source panel is not a root element of this asset\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/UILibraryEditor/ViewModels/UILibraryRootViewModel.cs","lineNumber":34,"sourceCode":"    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        }\n    }\n}\n","sourceCodeStart":16,"sourceCodeEnd":47,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/UILibraryEditor/ViewModels/UILibraryRootViewModel.cs#L16-L47","documentation":"Thrown by UILibraryRootViewModel.ReplaceRootElement when the sourcePanel's Id is not found among Asset.Asset.Hierarchy.RootParts. Unlike a UIPage, a UI library can have multiple root panels, and this method swaps an existing root panel (identified by index) for a new hierarchy, so the source panel must currently be a root.","triggerScenarios":"Calling ReplaceRootElement with a sourcePanel that is a nested (non-root) element of the library, or a panel belonging to another asset, so IndexOf(x => x.Id == sourcePanel.Id.ObjectId) returns -1.","commonSituations":"Editor drag/drop replacing a child panel instead of a root; stale PanelViewModel references after the library was restructured; passing a UIPage-style single-root assumption into library code.","solutions":["Pass a panel whose Id matches one of Asset.Asset.Hierarchy.RootParts.","Check Hierarchy.RootParts.Any(x => x.Id == sourcePanel.Id.ObjectId) before calling.","Refresh the view model references after library edits so the panel Ids are current."],"exampleFix":"// before\nlibraryRoot.ReplaceRootElement(nestedPanel, newHierarchy, targetPanelId);\n// after\nvar root = libraryRoot.Asset.Asset.Hierarchy.RootParts.FirstOrDefault(x => x.Id == nestedPanel.Id.ObjectId);\nif (root == null) throw new ArgumentException(\"Panel is not a root of this library\");\nlibraryRoot.ReplaceRootElement(nestedPanel, newHierarchy, targetPanelId);","handlingStrategy":"validation","validationCode":"bool isRoot = libraryRoot.Asset.Asset.Hierarchy.RootParts.Any(x => x.Id == sourcePanel.Id.ObjectId);","typeGuard":"static bool IsLibraryRoot(UILibraryRootViewModel root, PanelViewModel p) => root.Asset.Asset.Hierarchy.RootParts.Any(x => x.Id == p.Id.ObjectId);","tryCatchPattern":"try { libraryRoot.ReplaceRootElement(panel, hierarchy, targetId); } catch (ArgumentException ex) { /* resolve an actual root panel */ }","preventionTips":["Only call ReplaceRootElement with panels listed in RootParts.","Re-resolve panel view models from the asset after edits instead of caching.","Keep library page/lib usage distinct: library roots differ from page roots."],"tags":["stride","ui-library","invalid-argument","root-element"],"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"}