{"record":{"id":"536ddb7e416007d9","repo":"dotnet/wpf","slug":"specified-argument-was-out-of-the-range-of-valid-values-536ddb","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'row') Grid row must be set between 0 and row maximum.","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'row'\\) Grid row must be set between 0 and row maximum\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsIPAddress.cs","lineNumber":175,"sourceCode":"        {\n            get\n            {\n                return !Misc.IsEnabled(_hwnd);\n            }\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            // NOTE: IPAddress has only 1 row\n            if (row != 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(row), row, SR.GridRowOutOfRange);\n            }\n\n            if (column < 0 || column >= OCTETCOUNT)\n            {\n                throw new ArgumentOutOfRangeException(nameof(column), column, SR.GridColumnOutOfRange);\n            }\n\n            // Note: GridItem position is in reverse from the hwnd position\n            // take this into account\n            column = OCTETCOUNT - (column + 1);\n            IntPtr hwndChild = GetChildWindowFromIndex(column);\n            if (hwndChild != IntPtr.Zero)\n            {\n                return new ByteEditBoxOverride(hwndChild, column);\n            }\n            return null;\n        }\n","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsIPAddress.cs#L157-L193","documentation":"The IP address grid has exactly one row (the control is a single row of 4 octet fields). IGridProvider.GetItem throws ArgumentOutOfRangeException with message SR.GridRowOutOfRange whenever row is not 0.","triggerScenarios":"Calling IGridProvider.GetItem(row, column) with any row other than 0 (e.g. row=1 or row=-1) on a WindowsIPAddress proxy.","commonSituations":"Generic grid-walking automation code iterating rows 0..RowCount when it already knows RowCount==1; copy-pasted test code from other grid controls.","solutions":["Only call GetItem with row=0 for IP address controls","Check GridPattern.Current.RowCount (always 1 here) before iterating","Catch ArgumentOutOfRangeException and treat non-zero rows as out of bounds","Generalize test code using RowCount instead of hardcoded bounds"],"exampleFix":"// before\nfor (int r = 0; r < 4; r++) grid.GetItem(r, c);\n// after\nint rows = grid.Current.RowCount; // 1 for IP address control\nfor (int r = 0; r < rows; r++) grid.GetItem(r, c);","handlingStrategy":"validation","validationCode":"if (row != 0) throw new ArgumentOutOfRangeException(nameof(row), row, \"IPAddress grid has exactly 1 row.\");","typeGuard":null,"tryCatchPattern":"try { grid.GetItem(row, col); }\ncatch (ArgumentOutOfRangeException) { /* out-of-bounds row: clamp to 0 or skip */ }","preventionTips":["Remember the IP grid always has RowCount==1","Iterate using GridPattern.RowCount/ColumnCount, not hardcoded numbers","Use 0-based indices","Catch ArgumentOutOfRangeException at grid-walk boundaries"],"tags":["uiautomation","argumentoutofrange","gridpattern","row"],"backgroundTag":"argument-out-of-range","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"}