dotnet/wpf · error · NotSupportedException
SR.DocumentViewerOnlySupportsFixedDocumentSequence
Error message
SR.DocumentViewerOnlySupportsFixedDocumentSequence
What it means
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.
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
Example fix
// before documentViewer.Document = flowDocument; // throws // after flowDocPageViewer.Document = flowDocument;
Defensive patterns
Strategy: validation
Validate before calling
bool ok = doc == null || doc is FixedDocument || doc is FixedDocumentSequence;
Type guard
bool IsFixedContent(object doc) => doc is FixedDocument || doc is FixedDocumentSequence || doc == null;
Try / catch
try { viewer.Document = doc; }
catch (NotSupportedException) { /* wrong document type */ } Prevention
- 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
When it happens
Trigger: Assigning a FlowDocument or other non-fixed document to DocumentViewer.Document; binding a FlowDocumentStream to a DocumentViewer in a template.
Common situations: Developers confusing DocumentViewer with FlowDocumentPageViewer/FlowDocumentScrollViewer and giving it flow content; switching document types at runtime from fixed to flow.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- SR.DocumentViewerStyleMustIncludeContentHost
- By default, ToolTip property does not support ToolTip…
- Cannot convert from type.
- Cannot convert to type.
- Cannot convert to type.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/61eb67a95b545683.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs:866
/// <summary>
/// Creates AutomationPeer (<see cref="UIElement.OnCreateAutomationPeer"/>)
/// </summary>
protected override AutomationPeer OnCreateAutomationPeer()
{
return new DocumentViewerAutomationPeer(this);
}
/// <summary>
/// Attaches DocumentGrid to our document when it changes.
/// </summary>
protected override void OnDocumentChanged()
{
// Validate the new document type
if (!(Document is FixedDocument) && !(Document is FixedDocumentSequence)
&& !(Document == null))
{
throw new NotSupportedException(SR.DocumentViewerOnlySupportsFixedDocumentSequence);
}
//Call the base so that TextEditors are attached.
base.OnDocumentChanged();
//Assign the content to DocumentGrid.
AttachContent();
// Update the toolbar with our current document state.
_findToolbar?.DocumentLoaded = (Document != null) ? true : false;
// We do not automatically go to the first page on the _first_ content
// assignment, for two reasons:
// 1) If this is the first assignment, then we're already there by default.
// 2) The user may have specified vertical or horizontal offsets in markup or
// otherwise (<DocumentViewer VerticalOffset="1000">) and we need to honor
// those settings.
if (!_firstDocumentAssignment)View on GitHub (pinned to 81131a70a4)