dotnet/wpf · error · ArgumentOutOfRangeException

args

Error message

args

What it means

PageCache.PaginationProgressDelegate checks the incoming PaginationProgressEventArgs for integer overflow: if args.Start + args.Count is negative (negative Start and/or Count combining below zero), it throws ArgumentOutOfRangeException("args"). This protects the page-change computation from corrupting page cache indices.

Solutions

  1. Fix the custom DocumentPaginator so PaginationProgressEventArgs has Start >= 0, Count >= 0, and a non-negative sum.
  2. Validate Start/Count before raising OnPaginationProgress in your paginator subclass.
  3. Clamp Start to >= 0 and never report a range ending below 0.
  4. For built-in paginators, apply .NET servicing updates or report the bug.

Example fix

// before
OnPaginationProgress(this, new PaginationProgressEventArgs(lastKnownStart - delta, count));

// after
int start = Math.Max(0, lastKnownStart - delta);
OnPaginationProgress(this, new PaginationProgressEventArgs(start, count));
Defensive patterns

Strategy: validation

Validate before calling

void SafeOnPaginationProgress(int start, int count)
{
    if (start < 0 || count < 0 || start + count < 0)
        throw new ArgumentOutOfRangeException(nameof(start));
    OnPaginationProgress(this, new PaginationProgressEventArgs(start, count));
}

Type guard

static bool IsValidProgressRange(PaginationProgressEventArgs a) => a != null && a.Start >= 0 && a.Count >= 0 && a.Start + a.Count >= 0;

Try / catch

try { paginator.OnPaginationProgress(this, args); }
catch (ArgumentOutOfRangeException) { /* fix Start/Count before re-raising */ }

Prevention

When it happens

Trigger: A paginator reports a PaginationProgress event whose Start + Count is negative (negative Start, negative Count, or their sum below 0) when PageCache processes it on the dispatcher.

Common situations: Custom DocumentPaginator implementations raising PaginationProgressEventArgs with incorrect Start/Count values (e.g. negative Start after re-pagination or content shrinkage).

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/PageCache.cs:362

            if (_isPaginationCompleted)
            {
                if (args.Start == 0)
                {
                    //Since we've started repaginating from the beginning of the document
                    //after pagination was completed, we can't assume we know
                    //the default page size anymore.
                    _isDefaultSizeKnown = false;
                    _dynamicPageSizes = false;
                }

                //Reset our IsPaginationCompleted flag since we just got a pagination event.
                _isPaginationCompleted = false;
            }

            //Check for integer overflow.
            if (args.Start + args.Count < 0)
            {
                throw new ArgumentOutOfRangeException("args");
            }

            //Create our list of changes.  We allocate space for 2 changes here
            //as we can have as many as two changes resulting from a Pagination event.
            List<PageCacheChange> changes = new List<PageCacheChange>(2);
            PageCacheChange change;

            //If we have pages to add or modify, do so now.
            if (args.Count > 0)
            {
                //If pagination has added new pages onto the end of the document, we
                //add new entries to our cache.
                if (args.Start >= _cache.Count)
                {
                    //Completely new pages, so we add new cache entries
                    change = AddRange(args.Start, args.Count);
                    if (change != null)
                    {

View on GitHub (pinned to 81131a70a4)