dotnet/wpf · error · ArgumentException

SR.OnlyFlowAndFixedSupported

Error message

SR.OnlyFlowAndFixedSupported

What it means

AnnotationDocumentPaginator only supports wrapping a DocumentPaginator for fixed content (FixedDocumentPaginator / FixedDocumentSequencePaginator) or flow content (FlowDocumentPaginator). The constructor throws ArgumentException for any other paginator implementation.

Solutions

  1. Pass a paginator from a FlowDocument, FixedDocument, or FixedDocumentSequence instead of a custom paginator.
  2. If custom content must be annotated, render it as a FixedDocument and use its paginator.
  3. If you cannot change the content type, implement annotation support manually via AnnotationStore and AnnotationService rather than this paginator.
  4. Wrap the original content in a FlowDocumentPageViewer/DocumentViewer to obtain a supported paginator.

Example fix

// before
var paginator = new MyCustomPaginator(doc);
var ap = new AnnotationDocumentPaginator(paginator, store, FlowDirection.LeftToRight);
// after
var paginator = ((FlowDocumentPageViewer)viewer).Document.DocumentPaginator; // FlowDocumentPaginator
var ap = new AnnotationDocumentPaginator(paginator, store, FlowDirection.LeftToRight);
Defensive patterns

Strategy: type-guard

Validate before calling

bool IsSupportedPaginator(DocumentPaginator p) => p is FlowDocumentPaginator or FixedDocumentPaginator or FixedDocumentSequencePaginator;

Type guard

bool IsSupportedPaginator(DocumentPaginator p) => p is FlowDocumentPaginator or FixedDocumentPaginator or FixedDocumentSequencePaginator;

Try / catch

try { var ap = new AnnotationDocumentPaginator(paginator, store, flowDir); } catch (ArgumentException ex) { log.Error("Unsupported paginator type for annotations: " + ex.Message); }

Prevention

When it happens

Trigger: new AnnotationDocumentPaginator(paginator, store, flowDirection) where paginator is a custom DocumentPaginator subclass or any paginator not derived from the three supported types.

Common situations: Developers implementing custom pagination (e.g. for custom printing layouts) and trying to annotate it, or passing a paginator wrapper around another paginator.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/a2ac905929816875. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationDocumentPaginator.cs:71

        /// </summary>
        /// <param name="originalPaginator">document to add annotations to</param>
        /// <param name="annotationStore">store to retrieve annotations from</param>
        public AnnotationDocumentPaginator(DocumentPaginator originalPaginator, AnnotationStore annotationStore) : this(originalPaginator, annotationStore, FlowDirection.LeftToRight)
        {
        }

        /// <summary>
        ///     Create an instance of AnnotationDocumentPaginator for a given document and annotation store.
        /// </summary>
        /// <param name="originalPaginator">document to add annotations to</param>
        /// <param name="annotationStore">store to retrieve annotations from</param>
        /// <param name="flowDirection"></param>
        public AnnotationDocumentPaginator(DocumentPaginator originalPaginator, AnnotationStore annotationStore, FlowDirection flowDirection)
        {
            _isFixedContent = originalPaginator is FixedDocumentPaginator || originalPaginator is FixedDocumentSequencePaginator;

            if (!_isFixedContent && !(originalPaginator is FlowDocumentPaginator))
                throw new ArgumentException(SR.OnlyFlowAndFixedSupported);

            _originalPaginator = originalPaginator;
            _annotationStore = annotationStore;
            _locatorManager = new LocatorManager(_annotationStore);
            _flowDirection = flowDirection;

            // Register for events
            _originalPaginator.GetPageCompleted += new GetPageCompletedEventHandler(HandleGetPageCompleted);
            _originalPaginator.ComputePageCountCompleted += new AsyncCompletedEventHandler(HandleComputePageCountCompleted);
            _originalPaginator.PagesChanged += new PagesChangedEventHandler(HandlePagesChanged);
        }

        #endregion Public Constructors

        //------------------------------------------------------
        //
        //  Public Properties
        //

View on GitHub (pinned to 81131a70a4)