dotnet/wpf · error · ArgumentException

SR.PaginatorMissingContentPosition

Error message

SR.PaginatorMissingContentPosition

What it means

DynamicDocumentPaginator.GetPageNumberAsync throws ArgumentException when the contentPosition parameter is ContentPosition.Missing (or null, via the preceding null check). Missing is a sentinel meaning 'no valid content position', not a real position that can be mapped to a page number, so it is rejected before calling GetPageNumber.

Solutions

  1. Check contentPosition != ContentPosition.Missing before calling GetPageNumberAsync
  2. Ensure the content element is inserted into the document (e.g. inside the FixedDocument/FlowDocument) before querying its position
  3. Handle the not-in-document case separately instead of calling the async API

Example fix

// before
paginator.GetPageNumberAsync(element.ContentPosition, userState);
// after
var pos = element.ContentPosition;
if (pos != null && pos != ContentPosition.Missing)
{
    paginator.GetPageNumberAsync(pos, userState);
}
Defensive patterns

Strategy: validation

Validate before calling

if (contentPosition == null || contentPosition == ContentPosition.Missing)
    throw new ArgumentException("contentPosition must be a valid position, not Missing.", nameof(contentPosition));

Type guard

bool IsValidContentPosition(ContentPosition p) => p != null && !ReferenceEquals(p, ContentPosition.Missing);

Try / catch

try { paginator.GetPageNumberAsync(contentPosition, null); }
catch (ArgumentException) { /* content not in document; handle separately */ }

Prevention

When it happens

Trigger: Calling paginator.GetPageNumberAsync(contentPosition, userState) with ContentPosition.Missing, often obtained from an API that returned the Missing sentinel when the object is not yet in the document's content tree.

Common situations: Calling BringIntoView-style flows before the element is loaded into the document; passing ContentPosition.Missing from a failed GetContentPosition call; querying the page number of detached content.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Documents/DynamicDocumentPaginator.cs:76

        /// <summary>
        /// Async version of <see cref="DynamicDocumentPaginator.GetPageNumber"/>
        /// </summary>
        /// <param name="contentPosition">Content position.</param>
        /// <param name="userState">Unique identifier for the asynchronous task.</param>
        /// <exception cref="ArgumentException">
        /// Throws ArgumentException if the ContentPosition does not exist within 
        /// this element�s tree.
        /// </exception>
        public virtual void GetPageNumberAsync(ContentPosition contentPosition, object userState)
        {
            int pageNumber;

            // Content position cannot be null.
            ArgumentNullException.ThrowIfNull(contentPosition);
            // Content position cannot be Missing.
            if (contentPosition == ContentPosition.Missing)
            {
                throw new ArgumentException(SR.PaginatorMissingContentPosition, nameof(contentPosition));
            }

            pageNumber = GetPageNumber(contentPosition);
            OnGetPageNumberCompleted(new GetPageNumberCompletedEventArgs(contentPosition, pageNumber, null, false, userState));
        }

        /// <summary>
        /// Returns the ContentPosition for the given page.
        /// </summary>
        /// <param name="page">Document page.</param>
        /// <returns>Returns the ContentPosition for the given page.</returns>
        /// <exception cref="ArgumentException">
        /// Throws ArgumentException if the page is not valid.
        /// </exception>
        public abstract ContentPosition GetPagePosition(DocumentPage page);

        /// <summary>
        /// Returns the ContentPosition for an object within the content.

View on GitHub (pinned to 81131a70a4)