{"record":{"id":"22f26e3cf17d6f97","repo":"stride3d/stride","slug":"the-given-source-panel-does-not-match-the-currently-set-root","errorCode":null,"errorMessage":"The given source panel does not match the currently set root element","messagePattern":"The given source panel does not match the currently set root element","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/UIPageEditor/ViewModels/UIPageRootViewModel.cs","lineNumber":43,"sourceCode":"        public UIPageRootViewModel([NotNull] UIEditorBaseViewModel editor, [NotNull] UIPageViewModel asset, UIElementDesign rootElement)\n            : base(editor, asset, rootElement?.Yield())\n        {\n            NotifyGameSidePartAdded().Forget();\n        }\n\n        /// <inheritdoc />\n        [NotNull]\n        public override string Name { get => \"UI Page\"; set => throw new NotSupportedException(\"Can't change the name of a UIPage object.\"); }\n\n        [CanBeNull]\n        public UIElementViewModel RootElement => RootElements.SingleOrDefault();\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            if (sourcePanel.Id.ObjectId != Asset.Asset.Hierarchy.RootParts.Single().Id)\n                throw new ArgumentException(@\"The given source panel does not match the currently set root element\", nameof(sourcePanel));\n\n            Asset.AssetHierarchyPropertyGraph.RemovePartFromAsset(sourcePanel.UIElementDesign);\n            Asset.AssetHierarchyPropertyGraph.AddPartToAsset(hierarchy.Parts, hierarchy.Parts[targetPanelId], null, Asset.Asset.Hierarchy.RootParts.Count);\n        }\n\n        /// <inheritdoc />\n        // ReSharper disable once RedundantAssignment\n        protected override bool CanAddOrInsertChildren(IReadOnlyCollection<object> children, ref string message)\n        {\n            if (RootElement != null)\n                return ((IAddChildViewModel)RootElement).CanAddChildren(children, AddChildModifiers.None, out message);\n\n            var count = children.Count;\n            if (count == 0)\n            {\n                message = \"Empty selection\";\n                return false;\n            }","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/UIPageEditor/ViewModels/UIPageRootViewModel.cs#L25-L61","documentation":"Thrown by UIPageRootViewModel.ReplaceRootElement when the given sourcePanel's Id does not match the single root element of the UIPage asset. A UIPage has exactly one root, and this method replaces that root, so it validates that the panel being removed is in fact the current root.","triggerScenarios":"Calling ReplaceRootElement with any panel other than the page's single root (e.g. a nested panel, or a panel from another asset/page) so sourcePanel.Id.ObjectId != RootParts.Single().Id.","commonSituations":"Reusing library-replacement logic on a UIPage with a non-root panel; stale panel references after the root was already replaced once; drag/drop handlers targeting inner panels.","solutions":["Pass the panel corresponding to Asset.Asset.Hierarchy.RootParts.Single() as sourcePanel.","Verify sourcePanel.Id.ObjectId equals RootParts.Single().Id before calling.","Re-resolve the root PanelViewModel from the current asset state instead of caching it."],"exampleFix":"// before\npageRoot.ReplaceRootElement(somePanel, newHierarchy, targetPanelId);\n// after\nvar rootId = pageRoot.Asset.Asset.Hierarchy.RootParts.Single().Id;\nif (somePanel.Id.ObjectId != rootId) throw new ArgumentException(\"Not the current root\");\npageRoot.ReplaceRootElement(somePanel, newHierarchy, targetPanelId);","handlingStrategy":"validation","validationCode":"bool isCurrentRoot = sourcePanel.Id.ObjectId == pageRoot.Asset.Asset.Hierarchy.RootParts.Single().Id;","typeGuard":"static bool IsCurrentRoot(UIPageRootViewModel root, PanelViewModel p) => p.Id.ObjectId == root.Asset.Asset.Hierarchy.RootParts.Single().Id;","tryCatchPattern":"try { pageRoot.ReplaceRootElement(panel, hierarchy, targetId); } catch (ArgumentException ex) { /* pass the actual root panel */ }","preventionTips":["Resolve the root PanelViewModel from RootParts.Single() at call time.","Never reuse panel references after a previous root replacement.","Keep library-style multi-root logic out of UIPage flows."],"tags":["stride","ui-page","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"}