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 'column') Grid column must be set between 0 and column maximum.

What it means

WindowsIPAddress's IGridProvider.GetItem throws ArgumentOutOfRangeException when the column index is outside the valid range 0–3 (OCTETCOUNT): an IP address grid has four columns, one per octet, and only row 0. The automation client passed a column beyond the grid bounds.

Solutions

  1. Use 0-based columns 0..3 (OCTETCOUNT-1)
  2. Check GridPattern.Current.ColumnCount before iterating
  3. Catch ArgumentOutOfRangeException and clamp/log the bad column
  4. Remember GetItem internally reverses the column order (column = OCTETCOUNT - (column+1)) but expects 0-based input

Example fix

// before
var item = grid.GetItem(0, 4); // wrong: 1-based
// after
var item = grid.GetItem(0, 3); // 4th octet, 0-based
Defensive patterns

Strategy: validation

Validate before calling

if (column < 0 || column >= 4) throw new ArgumentOutOfRangeException(nameof(column), column, "IP grid columns are 0..3.");

Try / catch

try { grid.GetItem(row, column); }
catch (ArgumentOutOfRangeException) { /* out-of-bounds column: clamp to 0..3 */ }

Prevention

When it happens

Trigger: Calling IGridProvider.GetItem(row, column) with column = -1 or column >= 4 (e.g. assuming 8 or 32 fields, or 1-based indexing).

Common situations: Off-by-one errors using 1-based column indices (1..4 instead of 0..3); code reused from other grid controls with more columns.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/d74d5f7f1718bc48. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsIPAddress.cs:180

        }

        #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;
        }

        int IGridProvider.RowCount
        {
            get
            {
                return 1;

View on GitHub (pinned to 81131a70a4)