dotnet/wpf · error · NotSupportedException
SR.FlowDocumentPageViewerOnlySupportsFlowDocument
Error message
SR.FlowDocumentPageViewerOnlySupportsFlowDocument
What it means
SinglePageViewer (the print/preview viewer) can only host a FlowDocument. OnDocumentChanged validates the assigned Document and, if it is a fixed document (e.g. XpsDocument/FixedDocument) or other non-FlowDocument type, it resets Document to null and throws NotSupportedException.
Solutions
- Assign only FlowDocument instances to FlowDocumentPageViewer.
- For fixed/XPS documents use DocumentViewer or FlowDocumentReader alternatives that support FixedDocument.
- Parse XPS/fixed content into a FlowDocument if a flow viewer is required.
- Check the document type at runtime before assignment and route to the appropriate viewer.
Example fix
// before flowDocumentPageViewer.Document = xpsDocument.GetFixedDocumentSequence(); // after documentViewer.Document = xpsDocument.GetFixedDocumentSequence(); // or use a FlowDocument
Defensive patterns
Strategy: validation
Validate before calling
if (document is FlowDocument) flowDocumentPageViewer.Document = document; else documentViewer.Document = document;
Type guard
bool isFlowViewerCompatible = document is FlowDocument;
Try / catch
try { flowDocumentPageViewer.Document = document; }
catch (NotSupportedException) { documentViewer.Document = document; } Prevention
- Only assign FlowDocument to FlowDocumentPageViewer.
- Use DocumentViewer for fixed/XPS documents.
- Type-check documents before assignment.
- Don't interchange FlowDocumentPageViewer and DocumentViewer casually.
When it happens
Trigger: Assigning a FixedDocument, XpsDocument, or any non-FlowDocument IDocumentProvider/IDocumentPaginatorSource Document to a FlowDocumentPageViewer/SinglePageViewer; binding the Document property to a FixedDocumentViewer's content.
Common situations: Mixing up FlowDocumentPageViewer with DocumentViewer when previewing fixed/XPS documents; refactor that swapped a DocumentViewer for a FlowDocumentPageViewer while still loading XPS files.
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
- By default, ToolTip property does not support ToolTip…
- Cannot convert from type.
- Cannot convert to type.
- Cannot convert to type.
- CollectionIsFixedSize
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/473ee689a602b884.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SinglePageViewer.cs:507
if (_oldDocument != null)
{
DynamicDocumentPaginator dynamicDocumentPaginator = _oldDocument.DocumentPaginator as DynamicDocumentPaginator;
dynamicDocumentPaginator?.GetPageNumberCompleted -= new GetPageNumberCompletedEventHandler(HandleGetPageNumberCompleted);
FlowDocumentPaginator flowDocumentPaginator = _oldDocument.DocumentPaginator as FlowDocumentPaginator;
flowDocumentPaginator?.BreakRecordTableInvalidated -= new BreakRecordTableInvalidatedEventHandler(HandleAllBreakRecordsInvalidated);
}
base.OnDocumentChanged();
_oldDocument = Document;
// Validate the new document type
if (Document != null && !(Document is FlowDocument))
{
// Undo new document assignment.
Document = null;
// Throw exception.
throw new NotSupportedException(SR.FlowDocumentPageViewerOnlySupportsFlowDocument);
}
if(Document != null)
{
DynamicDocumentPaginator dynamicDocumentPaginator = Document.DocumentPaginator as DynamicDocumentPaginator;
dynamicDocumentPaginator?.GetPageNumberCompleted += new GetPageNumberCompletedEventHandler(HandleGetPageNumberCompleted);
FlowDocumentPaginator flowDocumentPaginator = Document.DocumentPaginator as FlowDocumentPaginator;
flowDocumentPaginator?.BreakRecordTableInvalidated += new BreakRecordTableInvalidatedEventHandler(HandleAllBreakRecordsInvalidated);
}
// Update the toolbar with our current document state.
if (!CanShowFindToolBar)
{
// Disable FindToolBar, if the content does not support it.
if (FindToolBar != null)
{
ToggleFindToolBar(false);View on GitHub (pinned to 81131a70a4)