dotnet/wpf · error · ArgumentOutOfRangeException

ArgumentOutOfRangeException(parameterName)

Error message

ArgumentOutOfRangeException(parameterName)

What it means

RibbonTabsPanel.ValidateInputOffset throws ArgumentOutOfRangeException(parameterName) when the supplied scroll offset is double.NaN, then otherwise clamps negatives to 0. It validates offsets arriving through the panel's IScrollInfo implementation (SetHorizontalOffset/SetVerticalOffset and related scroll methods).

Solutions

  1. Pass a finite offset; use the panel's current HorizontalOffset/VerticalOffset when the target is unknown.
  2. Validate with double.IsFinite (or !double.IsNaN) before calling and fall back to 0 or the current offset.
  3. Fix the NaN source: avoid dividing by zero extents and initialize measure-dependent values before scrolling.

Example fix

// before
ribbonTabsPanel.SetHorizontalOffset(targetOffset); // targetOffset may be NaN
// after
if (!double.IsNaN(targetOffset))
{
    ribbonTabsPanel.SetHorizontalOffset(targetOffset);
}
Defensive patterns

Strategy: validation

Validate before calling

var safeOffset = double.IsNaN(target) ? ribbonTabsPanel.HorizontalOffset : target;
ribbonTabsPanel.SetHorizontalOffset(safeOffset);

Type guard

static bool IsUsableOffset(double d) => !double.IsNaN(d);

Try / catch

try { panel.SetVerticalOffset(target); }
catch (ArgumentOutOfRangeException) { panel.SetVerticalOffset(panel.VerticalOffset); }

Prevention

When it happens

Trigger: Invoking scroll methods on RibbonTabsPanel with a NaN offset — e.g. SetHorizontalOffset(NaN), SetVerticalOffset(NaN), or internal callers (newValue path) computing a NaN target offset from invalid item/viewport measurements.

Common situations: Programmatic scrolling of ribbon tabs, animation or data-driven scroll offsets that yield NaN, or custom navigation logic hitting zero-size measures (0/0).

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonTabsPanel.cs:297

        {
            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
    }

    //-----------------------------------------------------------
    // ScrollData class
    //-----------------------------------------------------------
    #region ScrollData

    // Helper class to hold scrolling data.
    // This class exists to reduce working set when SCP is delegating to another implementation of ISI.
    // Standard "extra pointer always for less data sometimes" cache savings model:
    internal class ScrollData
    {

View on GitHub (pinned to 81131a70a4)