stride3d/stride · error · NotSupportedException
NotSupportedException
Error message
NotSupportedException
What it means
UIBaseViewModel.ResolveInsertionIndex computes where to insert a UI element. If the visual parent is neither an IContentControl-like host nor a Panel (e.g. it is a ContentPresenter, Border, or other non-Panel container that exposes no children collection), no index can be resolved and it throws NotSupportedException. This is a deliberate fail-fast for unsupported visual-tree parents.
Solutions
- Wrap the insertion target in a Panel-derived container (Grid/StackPanel) so the parent resolves as Panel.
- Insert the element before it is wrapped, or target the actual Panel inside the template via FindAncestor/FindName.
- Ensure the element is added to the visual tree (loaded) before calling InsertUIElement so parent is final.
- If you own a custom container, derive it from Panel to gain Children-based insertion support.
Example fix
// before viewModel.InsertUIElement(myControl, borderHost, index); // Border is not a Panel // after var grid = new Grid(); grid.Children.Add(myControl); borderHost.Child = grid; viewModel.InsertUIElement(myControl, grid, index);
Defensive patterns
Strategy: validation
Validate before calling
if (!(parent is Panel) && !(parent is IContentControl))
throw new InvalidOperationException($"Parent {parent.GetType().Name} is not a supported insertion container");
viewModel.InsertUIElement(element, parent, index); Type guard
bool IsInsertableContainer(object o) => o is Panel || o is IContentControl;
Prevention
- Author XAML templates so dynamic elements live under Panel-derived containers.
- Perform insertions after the view Loaded event so the visual tree is final.
- Avoid inserting directly into Border/ContentPresenter wrappers.
When it happens
Trigger: Calling InsertUIElement (or InsertUIElementBefore/After) with a parent element whose XAML visual parent is not a Panel (not Grid/StackPanel/Canvas/etc.) and not a supported content control, or while the element is not yet attached to the visual tree so parent resolution lands on an unsupported type.
Common situations: Inserting a control inside a Border or ContentControl wrapper; inserting while the target container is still in a template (ContentPresenter); calling before the view is loaded so parent is a transitional visual type; custom panels that don't derive from Panel.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Unable to reach the ItemsPresenter of the associated…
- Unable to reach the VirtualizingTilePanel of the associated…
- The given window does not contain a ContentPresenter.
- Value cannot be null. (Parameter 'getChildrenCountFunc')
- Value cannot be null. (Parameter 'getChildFunc')
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/4677d5727803efd6.
Report an issue: GitHub.
Appendix: source
Thrown at sources/editor/Stride.Assets.Presentation/ViewModel/UIBaseViewModel.cs:77
/// <returns>The index in which to insert a child.</returns>
private int ResolveInsertionIndex(UIElement parent, int index)
{
if (parent == null)
{
return index >= 0 ? index : Asset.Hierarchy.RootParts.Count;
}
var control = parent as ContentControl;
if (control != null)
{
return index >= 0 ? index : 0;
}
var panel = parent as Panel;
if (panel != null)
{
return index >= 0 ? index : panel.Children.Count;
}
throw new NotSupportedException();
}
}
}
View on GitHub (pinned to 96fad776d2)