{"record":{"id":"48d6ba5350b6e179","repo":"dotnet/wpf","slug":"argumentoutofrangeexception-nameof-args","errorCode":null,"errorMessage":"ArgumentOutOfRangeException(nameof(args))","messagePattern":"ArgumentOutOfRangeException\\(nameof\\(args\\)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs","lineNumber":2950,"sourceCode":"\n            InvalidateDocumentScrollInfo();\n        }\n\n        /// <summary>\n        /// When a new RowLayout has finished being computed we scale the layout such that it\n        /// fits within our window.\n        /// </summary>\n        /// <param name=\"source\"></param>\n        /// <param name=\"args\"></param>\n        private void OnRowLayoutCompleted(object source, RowLayoutCompletedEventArgs args)\n        {\n            if (args == null)\n            {\n                return;\n            }\n            if (args.PivotRowIndex >= _rowCache.RowCount)\n            {\n                throw new ArgumentOutOfRangeException(nameof(args));\n            }\n\n            //Get the pivot row\n            RowInfo pivotRow = _rowCache.GetRow(args.PivotRowIndex);\n\n            //If this row is not clean, and we're not applying a\n            //Zoom to the content then we need to rescale the layout when the\n            //pages on this row are retrieved.\n            if (!RowIsClean(pivotRow) && _documentLayout.ViewMode != ViewMode.Zoom)\n            {\n                //Save off this row in case we need to rescale due to\n                //dirty cache entries becoming clean (i.e. page sizes changing\n                //due to the cached size being an inaccurate guess.)\n                //OnRowCacheChanged will check this row to ensure that it gets scaled\n                //properly when all the pages on the row become available.\n                _savedPivotRow = pivotRow;\n            }\n            else","sourceCodeStart":2932,"sourceCodeEnd":2968,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs#L2932-L2968","documentation":"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).","triggerScenarios":"Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentGrid.cs:2950 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ignore stale RowLayoutCompleted events (check a layout generation/version counter before using args)","Recompute the row layout when the row count changed during async layout instead of acting on the stale pivot"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}