stride3d/stride · error · ArgumentException
The given source panel does not match the currently set…
Error message
The given source panel does not match the currently set root element
What it means
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.
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.
Example fix
// before
pageRoot.ReplaceRootElement(somePanel, newHierarchy, targetPanelId);
// after
var rootId = pageRoot.Asset.Asset.Hierarchy.RootParts.Single().Id;
if (somePanel.Id.ObjectId != rootId) throw new ArgumentException("Not the current root");
pageRoot.ReplaceRootElement(somePanel, newHierarchy, targetPanelId); Defensive patterns
Strategy: validation
Validate before calling
bool isCurrentRoot = sourcePanel.Id.ObjectId == pageRoot.Asset.Asset.Hierarchy.RootParts.Single().Id;
Type guard
static bool IsCurrentRoot(UIPageRootViewModel root, PanelViewModel p) => p.Id.ObjectId == root.Asset.Asset.Hierarchy.RootParts.Single().Id;
Try / catch
try { pageRoot.ReplaceRootElement(panel, hierarchy, targetId); } catch (ArgumentException ex) { /* pass the actual root panel */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- The given source panel is not a root element of this asset.
- Can't change the name of a UIPage object.
- A UIPage asset can't have more than one root.
- Custom strides is not supported with packed PixelFormats
- Unable to find the base
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/22f26e3cf17d6f97.
Report an issue: GitHub.
Appendix: source
Thrown at sources/editor/Stride.Assets.Presentation/AssetEditors/UIPageEditor/ViewModels/UIPageRootViewModel.cs:43
public UIPageRootViewModel([NotNull] UIEditorBaseViewModel editor, [NotNull] UIPageViewModel asset, UIElementDesign rootElement)
: base(editor, asset, rootElement?.Yield())
{
NotifyGameSidePartAdded().Forget();
}
/// <inheritdoc />
[NotNull]
public override string Name { get => "UI Page"; set => throw new NotSupportedException("Can't change the name of a UIPage object."); }
[CanBeNull]
public UIElementViewModel RootElement => RootElements.SingleOrDefault();
/// <inheritdoc />
public override void ReplaceRootElement(PanelViewModel sourcePanel, AssetCompositeHierarchyData<UIElementDesign, UIElement> hierarchy, Guid targetPanelId)
{
if (sourcePanel == null) throw new ArgumentNullException(nameof(sourcePanel));
if (sourcePanel.Id.ObjectId != Asset.Asset.Hierarchy.RootParts.Single().Id)
throw new ArgumentException(@"The given source panel does not match the currently set root element", nameof(sourcePanel));
Asset.AssetHierarchyPropertyGraph.RemovePartFromAsset(sourcePanel.UIElementDesign);
Asset.AssetHierarchyPropertyGraph.AddPartToAsset(hierarchy.Parts, hierarchy.Parts[targetPanelId], null, Asset.Asset.Hierarchy.RootParts.Count);
}
/// <inheritdoc />
// ReSharper disable once RedundantAssignment
protected override bool CanAddOrInsertChildren(IReadOnlyCollection<object> children, ref string message)
{
if (RootElement != null)
return ((IAddChildViewModel)RootElement).CanAddChildren(children, AddChildModifiers.None, out message);
var count = children.Count;
if (count == 0)
{
message = "Empty selection";
return false;
}View on GitHub (pinned to 96fad776d2)