dotnet/wpf · error · InvalidOperationException
SR.FrameNoAddChild
Error message
SR.FrameNoAddChild
What it means
Frame overrides AddChild and unconditionally throws this InvalidOperationException: a Frame does not support object children. Navigation content is supplied through the Source property or Navigate(), not by adding child elements, so XAML child elements inside <Frame> are rejected.
Solutions
- Set frame.Source = new Uri("Page1.xaml", UriKind.Relative) instead of adding children.
- Use frame.Navigate(pageOrUri) to display content.
- If you only need static hosted content without navigation, use a ContentControl or similar container instead of Frame.
Example fix
<!-- before: throws --> <Frame> <TextBlock Text="hello"/> </Frame> <!-- after --> <Frame Source="Page1.xaml"/> <!-- or --> <ContentControl> <TextBlock Text="hello"/> </ContentControl>
Defensive patterns
Strategy: validation
Validate before calling
// Never add children to Frame; set content via Source/Navigate. if (content is Uri uri) frame.Source = uri; else frame.Navigate(content);
Try / catch
try { frame.AddChild(value); }
catch (InvalidOperationException) { frame.Navigate(value); } Prevention
- Use Frame.Source or Frame.Navigate for content; never nest child elements in <Frame>.
- Use ContentControl when static embedded content is what you need.
- Grep XAML for inner elements inside Frame tags during migration from other containers.
When it happens
Trigger: Declaring child elements directly inside <Frame>...</Frame> in XAML, or calling frame.AddChild(...) / AddText programmatically.
Common situations: Migrating markup from another ContentControl (e.g. swapping a ContentControl for a Frame but keeping inner elements); trying to embed static content in a Frame instead of using Source="page.xaml" or Navigate.
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
- SR.InvalidOperation_NoJournal
- Animation_NoTextChildren
- Animation_NoTextChildren
- Can only call SelectAll when SelectionMode is Multiple or…
- Cannot read Page properties because it is not in a tree…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/41a98f2380dbde2b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Frame.cs:537
// Protected Methods
//
//------------------------------------------------------
#region Protected Methods
/// <summary>
/// Creates AutomationPeer (<see cref="UIElement.OnCreateAutomationPeer"/>)
/// </summary>
protected override AutomationPeer OnCreateAutomationPeer()
{
return new FrameAutomationPeer(this);
}
/// <summary>
/// Add an object child to this control
/// </summary>
protected override void AddChild(object value)
{
throw new InvalidOperationException(SR.FrameNoAddChild);
}
/// <summary>
/// Add a text string to this control
/// </summary>
protected override void AddText(string text)
{
XamlSerializerUtil.ThrowIfNonWhiteSpaceInAddText(text, this);
}
#endregion
#region Event Handlers
private void _OnBPReady(Object o, BPReadyEventArgs e)
{
// update content property
SetCurrentValueInternal(ContentProperty, e.Content);
View on GitHub (pinned to 81131a70a4)