dotnet/wpf · error · ArgumentOutOfRangeException
Specified argument was out of the range of valid values…
Error message
Specified argument was out of the range of valid values. (Parameter 'row') Grid row must be set between 0 and row maximum.
What it means
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.
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
Example fix
// before for (int r = 0; r < 4; r++) grid.GetItem(r, c); // after int rows = grid.Current.RowCount; // 1 for IP address control for (int r = 0; r < rows; r++) grid.GetItem(r, c);
Defensive patterns
Strategy: validation
Validate before calling
if (row != 0) throw new ArgumentOutOfRangeException(nameof(row), row, "IPAddress grid has exactly 1 row.");
Try / catch
try { grid.GetItem(row, col); }
catch (ArgumentOutOfRangeException) { /* out-of-bounds row: clamp to 0 or skip */ } Prevention
- 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
When it happens
Trigger: Calling IGridProvider.GetItem(row, column) with any row other than 0 (e.g. row=1 or row=-1) on a WindowsIPAddress proxy.
Common situations: Generic grid-walking automation code iterating rows 0..RowCount when it already knows RowCount==1; copy-pasted test code from other grid controls.
Related errors
- Specified argument was out of the range of valid values…
- Specified argument was out of the range of valid values…
- Specified argument was out of the range of valid values…
- SR.GridColumnOutOfRange
- SR.GridRowOutOfRange
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/536ddb7e416007d9.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsIPAddress.cs:175
{
get
{
return !Misc.IsEnabled(_hwnd);
}
}
#endregion
#region Grid Pattern
// Obtain the AutomationElement at an zero based absolute position in the grid.
// Where 0,0 is top left
IRawElementProviderSimple IGridProvider.GetItem(int row, int column)
{
// NOTE: IPAddress has only 1 row
if (row != 0)
{
throw new ArgumentOutOfRangeException(nameof(row), row, SR.GridRowOutOfRange);
}
if (column < 0 || column >= OCTETCOUNT)
{
throw new ArgumentOutOfRangeException(nameof(column), column, SR.GridColumnOutOfRange);
}
// Note: GridItem position is in reverse from the hwnd position
// take this into account
column = OCTETCOUNT - (column + 1);
IntPtr hwndChild = GetChildWindowFromIndex(column);
if (hwndChild != IntPtr.Zero)
{
return new ByteEditBoxOverride(hwndChild, column);
}
return null;
}
View on GitHub (pinned to 81131a70a4)