dotnet/wpf · error · ArgumentOutOfRangeException

SR.GridColumnOutOfRange

Error message

SR.GridColumnOutOfRange

What it means

IGridProvider.GetItem on the Win32 status bar proxy validates the column index against the number of panes (Count). A column less than 0 or greater than or equal to the pane count throws ArgumentOutOfRangeException with SR.GridColumnOutOfRange.

Solutions

  1. Query the pane count (e.g. via IGridProvider.ColumnCount) and clamp the column before calling GetItem.
  2. Use UIA find-all on child pane elements instead of raw grid coordinates when the layout is dynamic.
  3. Guard the column loop bound with ColumnCount rather than a hard-coded value.

Example fix

// before
var pane = grid.GetItem(0, 3);
// after
if (col >= 0 && col < grid.ColumnCount) { var pane = grid.GetItem(0, col); }
Defensive patterns

Strategy: validation

Validate before calling

var grid = statusBar.GetCurrentPattern(GridPattern.Pattern) as GridPattern;
if (column >= 0 && column < grid.ColumnCount) { var pane = grid.GetItem(0, column); }

Type guard

static bool IsValidColumn(GridPattern g, int col) => col >= 0 && col < g.ColumnCount;

Try / catch

try { grid.GetItem(0, col); }
catch (ArgumentOutOfRangeException) { /* pane does not exist */ }

Prevention

When it happens

Trigger: Calling IGridProvider.GetItem(0, column) with column < 0 or column >= the number of status bar panes.

Common situations: Assuming a fixed pane count (e.g. always 3 parts) while the application shows a different number; off-by-one loops; panes removed after a UI update while cached column indices are reused.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsStatusBar.cs:260

        }

        #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: Status bar has only 1 row
            if (row != 0)
            {
                throw new ArgumentOutOfRangeException(nameof(row), row, SR.GridRowOutOfRange);
            }

            if (column < 0 || column >= Count)
            {
                throw new ArgumentOutOfRangeException(nameof(column), column, SR.GridColumnOutOfRange);
            }

            return CreateStatusBarPane(column);
        }

        int IGridProvider.RowCount
        {
            get
            {
                return 1;
            }
        }

        int IGridProvider.ColumnCount
        {
            get
            {
                return Count;

View on GitHub (pinned to 81131a70a4)