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

  1. Assign only FlowDocument instances to FlowDocumentPageViewer.
  2. For fixed/XPS documents use DocumentViewer or FlowDocumentReader alternatives that support FixedDocument.
  3. Parse XPS/fixed content into a FlowDocument if a flow viewer is required.
  4. 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

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


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)