{"record":{"id":"473ee689a602b884","repo":"dotnet/wpf","slug":"sr-flowdocumentpagevieweronlysupportsflowdocument","errorCode":null,"errorMessage":"SR.FlowDocumentPageViewerOnlySupportsFlowDocument","messagePattern":"SR\\.FlowDocumentPageViewerOnlySupportsFlowDocument","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SinglePageViewer.cs","lineNumber":507,"sourceCode":"            if (_oldDocument != null)\n            {\n                DynamicDocumentPaginator dynamicDocumentPaginator = _oldDocument.DocumentPaginator as DynamicDocumentPaginator;\n                dynamicDocumentPaginator?.GetPageNumberCompleted -= new GetPageNumberCompletedEventHandler(HandleGetPageNumberCompleted);\n\n                FlowDocumentPaginator flowDocumentPaginator = _oldDocument.DocumentPaginator as FlowDocumentPaginator;\n                flowDocumentPaginator?.BreakRecordTableInvalidated -= new BreakRecordTableInvalidatedEventHandler(HandleAllBreakRecordsInvalidated);\n            }\n\n            base.OnDocumentChanged();\n            _oldDocument = Document;\n\n            // Validate the new document type\n            if (Document != null && !(Document is FlowDocument))\n            {\n                // Undo new document assignment.\n                Document = null;\n                // Throw exception.\n                throw new NotSupportedException(SR.FlowDocumentPageViewerOnlySupportsFlowDocument);\n            }\n\n            if(Document != null)\n            {\n                DynamicDocumentPaginator dynamicDocumentPaginator = Document.DocumentPaginator as DynamicDocumentPaginator;\n                dynamicDocumentPaginator?.GetPageNumberCompleted += new GetPageNumberCompletedEventHandler(HandleGetPageNumberCompleted);\n\n                FlowDocumentPaginator flowDocumentPaginator = Document.DocumentPaginator as FlowDocumentPaginator;\n                flowDocumentPaginator?.BreakRecordTableInvalidated += new BreakRecordTableInvalidatedEventHandler(HandleAllBreakRecordsInvalidated);\n            }\n\n            // Update the toolbar with our current document state.\n            if (!CanShowFindToolBar)\n            {\n                // Disable FindToolBar, if the content does not support it.\n                if (FindToolBar != null)\n                {\n                    ToggleFindToolBar(false);","sourceCodeStart":489,"sourceCodeEnd":525,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/SinglePageViewer.cs#L489-L525","documentation":"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.","triggerScenarios":"Assigning a FixedDocument, XpsDocument, or any non-FlowDocument IDocumentProvider/IDocumentPaginatorSource Document to a FlowDocumentPageViewer/SinglePageViewer; binding the Document property to a FixedDocumentViewer's content.","commonSituations":"Mixing up FlowDocumentPageViewer with DocumentViewer when previewing fixed/XPS documents; refactor that swapped a DocumentViewer for a FlowDocumentPageViewer while still loading XPS files.","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."],"exampleFix":"// before\nflowDocumentPageViewer.Document = xpsDocument.GetFixedDocumentSequence();\n// after\ndocumentViewer.Document = xpsDocument.GetFixedDocumentSequence(); // or use a FlowDocument","handlingStrategy":"validation","validationCode":"if (document is FlowDocument) flowDocumentPageViewer.Document = document;\nelse documentViewer.Document = document;","typeGuard":"bool isFlowViewerCompatible = document is FlowDocument;","tryCatchPattern":"try { flowDocumentPageViewer.Document = document; }\ncatch (NotSupportedException) { documentViewer.Document = document; }","preventionTips":["Only assign FlowDocument to FlowDocumentPageViewer.","Use DocumentViewer for fixed/XPS documents.","Type-check documents before assignment.","Don't interchange FlowDocumentPageViewer and DocumentViewer casually."],"tags":["wpf","document","not-supported"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}