{"record":{"id":"d8ff56a3f1b4d0ac","repo":"dotnet/wpf","slug":"sr-gridrowoutofrange-windowscalendar","errorCode":null,"errorMessage":"SR.GridRowOutOfRange","messagePattern":"SR\\.GridRowOutOfRange","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/UnsupportedAutomationProxies/WindowsCalendar.cs","lineNumber":2515,"sourceCode":"                }\n                else\n                {\n                    lastChild = new CalendarDay(_hwnd, this, TOTAL_CELLS - 1, _iCalendar);\n                }\n                return lastChild;\n            }\n\n            #endregion\n\n            #region Grid Pattern\n\n            // Obtain the AutomationElement at an zero based absolute position in the grid.  \n            // Where 0,0 is top left\n            IRawElementProviderSimple IGridProvider.GetItem(int row, int column)\n            {\n                if (row < 0 || row >= MAX_WEEKS)\n                {\n                    throw new ArgumentOutOfRangeException(\"row\", row, SR.GridRowOutOfRange);\n                }\n\n                if (column < 0 || column >= MAX_DAYS)\n                {\n                    throw new ArgumentOutOfRangeException(\"column\", column, SR.GridColumnOutOfRange);\n                }\n\n                int dayIndex = CalendarDay.DayIndexFromRowColumn(row, column);\n                return CreateCalendarDay(dayIndex);\n            }\n\n            // Number of Rows for the grid\n            int IGridProvider.RowCount\n            {\n                get\n                {\n                    return MAX_WEEKS;\n                }","sourceCodeStart":2497,"sourceCodeEnd":2533,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/UnsupportedAutomationProxies/WindowsCalendar.cs#L2497-L2533","documentation":"IGridProvider.GetItem on WindowsCalendar validates the row index against MAX_WEEKS (6). A row outside 0..MAX_WEEKS-1 raises ArgumentOutOfRangeException with message SR.GridRowOutOfRange, because the MonthCalendar grid only has a fixed number of week rows.","triggerScenarios":"Calling IGridProvider.GetItem(row, column) on the calendar element with row < 0 or row >= MAX_WEEKS (e.g. row 6 or 7 when at most 6 weeks exist).","commonSituations":"UIA clients computing grid coordinates from screen positions or iterating rows without consulting the grid's RowCount property; assumptions based on other grid controls.","solutions":["Read GridPattern.RowCount from the element and keep row within 0..RowCount-1.","Clamp or validate the row index before calling GetItem.","Catch ArgumentOutOfRangeException and fall back to the valid range discovered via RowCount.","Use the element's supported children discovery (FindChildren) instead of guessing row indices."],"exampleFix":"// before\nvar item = gridPattern.GetItem(row, column);\n// after\nint rowCount = gridPattern.RowCount;\nif (row >= 0 && row < rowCount)\n{\n    var item = gridPattern.GetItem(row, column);\n}","handlingStrategy":"validation","validationCode":"if (row >= 0 && row < gridPattern.RowCount) { var item = gridPattern.GetItem(row, column); }","typeGuard":null,"tryCatchPattern":"try { gridPattern.GetItem(row, column); } catch (ArgumentOutOfRangeException) { /* clamp row to RowCount-1 */ }","preventionTips":["Always read GridPattern.RowCount/ColumnCount before indexing","Use 0-based indices consistently","Enumerate child elements instead of guessing grid coordinates"],"tags":["uiautomation","argumentoutofrange","grid"],"backgroundTag":"index-out-of-bounds","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}