dotnet/wpf · error

ArgumentOutOfRangeException(nameof(args))

Error message

ArgumentOutOfRangeException(nameof(args))

What it means

ArgumentOutOfRangeException from DocumentGrid.OnRowLayoutCompleted: the completed RowLayoutCompletedEventArgs carries a PivotRowIndex >= the row cache's RowCount, i.e. the async layout result references a row that no longer exists (stale or inconsistent row layout event).

Solutions

  1. Ignore stale RowLayoutCompleted events (check a layout generation/version counter before using args)
  2. Recompute the row layout when the row count changed during async layout instead of acting on the stale pivot
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs:2950 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs:2950

            InvalidateDocumentScrollInfo();
        }

        /// <summary>
        /// When a new RowLayout has finished being computed we scale the layout such that it
        /// fits within our window.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="args"></param>
        private void OnRowLayoutCompleted(object source, RowLayoutCompletedEventArgs args)
        {
            if (args == null)
            {
                return;
            }
            if (args.PivotRowIndex >= _rowCache.RowCount)
            {
                throw new ArgumentOutOfRangeException(nameof(args));
            }

            //Get the pivot row
            RowInfo pivotRow = _rowCache.GetRow(args.PivotRowIndex);

            //If this row is not clean, and we're not applying a
            //Zoom to the content then we need to rescale the layout when the
            //pages on this row are retrieved.
            if (!RowIsClean(pivotRow) && _documentLayout.ViewMode != ViewMode.Zoom)
            {
                //Save off this row in case we need to rescale due to
                //dirty cache entries becoming clean (i.e. page sizes changing
                //due to the cached size being an inaccurate guess.)
                //OnRowCacheChanged will check this row to ensure that it gets scaled
                //properly when all the pages on the row become available.
                _savedPivotRow = pivotRow;
            }
            else

View on GitHub (pinned to 81131a70a4)