{"record":{"id":"61eb67a95b545683","repo":"dotnet/wpf","slug":"sr-documentvieweronlysupportsfixeddocumentsequence","errorCode":null,"errorMessage":"SR.DocumentViewerOnlySupportsFixedDocumentSequence","messagePattern":"SR\\.DocumentViewerOnlySupportsFixedDocumentSequence","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs","lineNumber":866,"sourceCode":"\n        /// <summary>\n        /// Creates AutomationPeer (<see cref=\"UIElement.OnCreateAutomationPeer\"/>)\n        /// </summary>\n        protected override AutomationPeer OnCreateAutomationPeer()\n        {\n            return new DocumentViewerAutomationPeer(this);\n        }\n\n        /// <summary>\n        /// Attaches DocumentGrid to our document when it changes.\n        /// </summary>\n        protected override void OnDocumentChanged()\n        {\n            // Validate the new document type\n            if (!(Document is FixedDocument) && !(Document is FixedDocumentSequence)\n                && !(Document == null))\n            {\n                throw new NotSupportedException(SR.DocumentViewerOnlySupportsFixedDocumentSequence);\n            }\n\n            //Call the base so that TextEditors are attached.\n            base.OnDocumentChanged();\n\n            //Assign the content to DocumentGrid.\n            AttachContent();\n\n            // Update the toolbar with our current document state.\n            _findToolbar?.DocumentLoaded = (Document != null) ? true : false;\n\n            // We do not automatically go to the first page on the _first_ content\n            // assignment, for two reasons:\n            //  1) If this is the first assignment, then we're already there by default.\n            //  2) The user may have specified vertical or horizontal offsets in markup or\n            //     otherwise (<DocumentViewer VerticalOffset=\"1000\">) and we need to honor\n            //     those settings.\n            if (!_firstDocumentAssignment)","sourceCodeStart":848,"sourceCodeEnd":884,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs#L848-L884","documentation":"DocumentViewer only supports FixedDocument and FixedDocumentSequence content (plus null to clear). When Document is set to any other type (e.g. FlowDocument, FlowDocumentScrollViewer content), the OnDocumentChanged override throws NotSupportedException with SR.DocumentViewerOnlySupportsFixedDocumentSequence.","triggerScenarios":"Assigning a FlowDocument or other non-fixed document to DocumentViewer.Document; binding a FlowDocumentStream to a DocumentViewer in a template.","commonSituations":"Developers confusing DocumentViewer with FlowDocumentPageViewer/FlowDocumentScrollViewer and giving it flow content; switching document types at runtime from fixed to flow.","solutions":["Use FlowDocumentPageViewer or FlowDocumentScrollViewer for FlowDocument content","Only assign FixedDocument or FixedDocumentSequence instances to DocumentViewer.Document","Set Document to null when clearing instead of substituting another document type"],"exampleFix":"// before\ndocumentViewer.Document = flowDocument; // throws\n// after\nflowDocPageViewer.Document = flowDocument;","handlingStrategy":"validation","validationCode":"bool ok = doc == null || doc is FixedDocument || doc is FixedDocumentSequence;","typeGuard":"bool IsFixedContent(object doc) => doc is FixedDocument || doc is FixedDocumentSequence || doc == null;","tryCatchPattern":"try { viewer.Document = doc; }\ncatch (NotSupportedException) { /* wrong document type */ }","preventionTips":["Use FlowDocument viewers for flow content, DocumentViewer only for fixed","Check the document type before assigning Document","Keep document-type switching behind a viewer factory"],"tags":["wpf","documentviewer","not-supported"],"backgroundTag":"incompatible-source-type","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"}