HandyOrg/HandyControl · error · ArgumentOutOfRangeException

index

Error message

index

What it means

Argument guard in RangeTrack.GetVisualChild: throws (ArgumentOutOfRangeException, message 'index') when the requested visual child index is outside the _visualChildren array range or the array is null/has no child at that index. WPF's visual tree calls this with an index derived from VisualChildrenCount, so it fires when the reported count and the actual _visualChildren contents are out of sync.

Solutions

  1. Ensure VisualChildrenCount always matches the number of non-null entries actually stored in _visualChildren
  2. Rebuild _visualChildren (AddVisualChild/RemoveVisualChild) whenever thumb or button parts are added, removed or hidden
  3. Bounds-check index against VisualChildrenCount before indexing and return/throw base behavior for invalid indices
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/Shared/HandyControl_Shared/Controls/Slider/RangeSlider/RangeTrack.cs:180 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14). Data as JSON: /api/errors/398a922809c0352a. Report an issue: GitHub.

Appendix: source

Thrown at src/Shared/HandyControl_Shared/Controls/Slider/RangeSlider/RangeTrack.cs:180

        set => SetValue(ValueEndProperty, value);
    }

    public static readonly DependencyProperty IsDirectionReversedProperty = DependencyProperty.Register(
        nameof(IsDirectionReversed), typeof(bool), typeof(RangeTrack), new PropertyMetadata(ValueBoxes.FalseBox));

    public bool IsDirectionReversed
    {
        get => (bool) GetValue(IsDirectionReversedProperty);
        set => SetValue(IsDirectionReversedProperty, ValueBoxes.BooleanBox(value));
    }

    protected override Visual GetVisualChild(int index)
    {
        if (_visualChildren?[index] == null)
        {
            // ReSharper disable once UseNameofExpression
            // ReSharper disable once LocalizableElement
            throw new ArgumentOutOfRangeException("index", index, "ArgumentOutOfRange");
        }
        return _visualChildren[index];
    }

    protected override Size MeasureOverride(Size availableSize)
    {
        var desiredSize = new Size();

        // Only measure thumb
        // Repeat buttons will be sized based on thumb
        if (_thumbStart != null)
        {
            _thumbStart.Measure(availableSize);
            desiredSize = _thumbStart.DesiredSize;
        }

        if (_thumbEnd != null)
        {

View on GitHub (pinned to 2c0875ebd6)