dotnet/wpf · error · ArgumentOutOfRangeException

ArgumentOutOfRangeException(parameterName)

Error message

ArgumentOutOfRangeException(parameterName)

What it means

RibbonTabHeadersPanel.ValidateInputOffset rejects NaN offsets with ArgumentOutOfRangeException, naming the offending parameter. It is the panel's shared validation used by IScrollInfo members (SetHorizontalOffset, SetVerticalOffset, LineUp/Down, MakeVisible paths) that accept an offset double.

Solutions

  1. Never pass double.NaN; pass a finite value (e.g. HorizontalOffset or 0).
  2. Check double.IsNaN(offset) at the call site and clamp to the panel's current offset.
  3. Fix the upstream computation producing NaN (guard divisions, initialize scroll extents).

Example fix

// before
scrollInfo.SetHorizontalOffset(double.NaN);
// after
var offset = double.IsNaN(computed) ? scrollInfo.HorizontalOffset : computed;
scrollInfo.SetHorizontalOffset(offset);
Defensive patterns

Strategy: validation

Validate before calling

if (double.IsNaN(offset)) offset = ribbonTabHeadersPanel.HorizontalOffset;
ribbonTabHeadersPanel.SetHorizontalOffset(offset);

Type guard

static bool IsValidOffset(double d) => !double.IsNaN(d) && !double.IsInfinity(d);

Try / catch

try { panel.SetHorizontalOffset(offset); }
catch (ArgumentOutOfRangeException) { panel.SetHorizontalOffset(0); }

Prevention

When it happens

Trigger: Calling IScrollInfo methods on RibbonTabHeadersPanel (e.g. SetHorizontalOffset(double.NaN), SetVerticalOffset(NaN)) or internal scroll logic passing NaN — often from uninitialized scroll data or division by zero producing NaN.

Common situations: Custom scrolling/keyboard-navigation code driving the ribbon tab headers panel, or binding scroll offsets to computed values that evaluate to NaN (0/0, NaN propagation from transforms).

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonTabHeadersPanel.cs:1045

        {
            get { return 0.0; }
        }

        private ScrollData ScrollData
        {
            get
            {
                return _scrollData ?? (_scrollData = new ScrollData());
            }
        }

        private ScrollData _scrollData;

        internal static double ValidateInputOffset(double offset, string parameterName)
        {
            if (double.IsNaN(offset))
            {
                throw new ArgumentOutOfRangeException(parameterName);
            }

            return Math.Max(0.0, offset);
        }
        #endregion
    }
}

View on GitHub (pinned to 81131a70a4)