dotnet/wpf · error · InvalidOperationException
SR.PrevoiusPartialPageContentOutstanding
Error message
SR.PrevoiusPartialPageContentOutstanding
What it means
This InvalidOperationException is thrown when AddChild on FixedDocument is given a new partial PageContent while a previously added partial page has not yet finished initializing. FixedDocument supports only one outstanding partially-loaded page at a time because it must attach an Initialized handler and logical parent to exactly one pending page.
Solutions
- Wait for the previous partial page's Initialized event before adding the next PageContent
- Add fully initialized PageContent objects instead of partial ones
- Ensure no duplicate AddChild calls for the same pending page
- Catch InvalidOperationException and defer the add via a queue drained on page load
Example fix
// before
foreach (var pc in pageContents) fixedDocument.AddChild(pc); // throws if a partial page is pending
// after
void AddNext(IEnumerator<PageContent> e) {
if (!e.MoveNext()) return;
((IAddChild)fixedDocument).AddChild(e.Current);
Dispatcher.CurrentDispatcher.BeginInvoke(() => AddNext(e), System.Windows.Threading.DispatcherPriority.Loaded);
} Defensive patterns
Strategy: try-catch
Validate before calling
bool canAdd = fixedDocument._pages.All(p => p.IsInitialized); // check via public surface: only add PageContent once previous ones report Initialized
Try / catch
try { ((IAddChild)fixedDocument).AddChild(pageContent); } catch (InvalidOperationException) { pendingPages.Enqueue(pageContent); } Prevention
- Wait for the previous partial page's Initialized event before adding the next
- Avoid adding multiple asynchronous PageContent objects in a tight loop
- Queue page additions and drain them on page-load events
When it happens
Trigger: Adding multiple asynchronous/partial PageContent entries in quick succession (e.g. from async XPS loading) before the prior partial page's Initialized event fires.
Common situations: Async XPS document parsing or streaming scenarios; adding several page contents before UI/binder events complete; double-adding the same page content.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Cannot countersign an unsigned package.
- Cannot read Page properties because it is not in a tree…
- Cannot sign read-only file.
- Exception of type 'System.InvalidOperationException' was…
- Page can have only one child.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/083d6c6790a33f03.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs:154
throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, value.GetType(), typeof(PageContent)), nameof(value));
}
if (fp.IsInitialized)
{
_pages.Add(fp);
}
else
{
DocumentsTrace.FixedFormat.FixedDocument.Trace($"Page {_pages.Count} Deferred");
if (_partialPage == null)
{
_partialPage = fp;
_partialPage.ChangeLogicalParent(this);
_partialPage.Initialized += new EventHandler(OnPageLoaded);
}
else
{
throw new InvalidOperationException(SR.PrevoiusPartialPageContentOutstanding);
}
}
}
///<summary>
/// Called when text appears under the tag in markup
///</summary>
///<param name="text">
/// Text to Add to the Object
///</param>
/// <ExternalAPI/>
void IAddChild.AddText(string text)
{
XamlSerializerUtil.ThrowIfNonWhiteSpaceInAddText(text, this);
}
#endregion
#region IUriContextView on GitHub (pinned to 81131a70a4)