{"record":{"id":"2388e86f40b78c85","repo":"dotnet/wpf","slug":"sr-gridcolumnoutofrange-windowscalendar","errorCode":null,"errorMessage":"SR.GridColumnOutOfRange","messagePattern":"SR\\.GridColumnOutOfRange","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/UnsupportedAutomationProxies/WindowsCalendar.cs","lineNumber":2520,"sourceCode":"                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                }\n            }\n\n            // Number of Columns for the grid\n            int IGridProvider.ColumnCount\n            {","sourceCodeStart":2502,"sourceCodeEnd":2538,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/UnsupportedAutomationProxies/WindowsCalendar.cs#L2502-L2538","documentation":"WindowsCalendar's IGridProvider.GetItem throws ArgumentOutOfRangeException when the column index is outside 0..MAX_DAYS-1 (the calendar grid has one column per day of the week). The row check similarly bounds it to MAX_WEEKS. The automation client addressed a cell outside the calendar grid.","triggerScenarios":"Calling IGridProvider.GetItem(row, column) with column < 0 or column >= MAX_DAYS (e.g. column 7 for a 7-day week, zero-based).","commonSituations":"UIA clients assuming 1-based columns, or mapping screen coordinates to grid cells with off-by-one errors.","solutions":["Read GridPattern.ColumnCount (7) and keep column within 0..ColumnCount-1.","Validate/clamp the column index before calling GetItem.","Switch to 0-based indexing if coming from a 1-based mental model.","Catch ArgumentOutOfRangeException and correct the index in the caller."],"exampleFix":"// before\nvar item = gridPattern.GetItem(row, column); // column from 1..7\n// after\nvar item = gridPattern.GetItem(row, column - 1); // convert to 0-based","handlingStrategy":"validation","validationCode":"if (column >= 0 && column < gridPattern.ColumnCount) { var item = gridPattern.GetItem(row, column); }","typeGuard":null,"tryCatchPattern":"try { gridPattern.GetItem(row, column); } catch (ArgumentOutOfRangeException) { /* clamp column to ColumnCount-1 */ }","preventionTips":["Remember columns are 0-based (0..6 for a 7-day week)","Query ColumnCount dynamically rather than hardcoding","Convert from 1-based UI column numbers explicitly"],"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"}