dotnet/wpf · error · ArgumentException

Invalid priority range order.

Error message

Invalid priority range order.

What it means

After individually validating min and max, PriorityRange.Initialize enforces ordering: max must be >= min, otherwise it throws ArgumentException with SR.InvalidPriorityRangeOrder ('Invalid priority range order.'). Note DispatcherPriority's numeric values run from Invalid (-1) up to Send (10), so a range is expressed numerically ascending.

Solutions

  1. Order the bounds numerically: min should be the lower numeric value, max the higher (e.g. min: Background/4, max: Send/10).
  2. If the intent is 'from Send down to Normal', use Dispatcher.Unwrapped priority comparisons or iterate the range yourself instead of an inverted PriorityRange.
  3. Normalize inputs before constructing: if (min > max) swap them.

Example fix

// before
var range = new PriorityRange(DispatcherPriority.Send, true, DispatcherPriority.Background, true);
// after
var range = new PriorityRange(DispatcherPriority.Background, true, DispatcherPriority.Send, true);
Defensive patterns

Strategy: validation

Validate before calling

if (min > max)
    (min, max) = (max, min); // normalize before constructing the range

Type guard

static bool IsOrderedRange(DispatcherPriority min, DispatcherPriority max) => min <= max;

Try / catch

try
{
    var range = new PriorityRange(min, true, max, true);
}
catch (ArgumentException ex) when (ex.Message.Contains("range order"))
{
    logger.LogError(ex, "min ({Min}) exceeds max ({Max})", min, max);
    throw;
}

Prevention

When it happens

Trigger: new PriorityRange(DispatcherPriority.Send, true, DispatcherPriority.Normal, true) — passing bounds in descending order; arguments swapped at the call site; variables bound to the wrong values.

Common situations: Refactoring that reversed parameter order; assuming enum declaration order equals numeric order; dynamic construction where user input supplies min/max and can be inverted.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/PriorityRange.cs:286

            if (!max.IsValid)
            {
                throw new ArgumentException("Invalid priority.", "max");
            }
            */
            if(max < DispatcherPriority.Invalid || max > DispatcherPriority.Send)
            {
                // If we move to a Priority class, this exception will have to change too.
                throw new System.ComponentModel.InvalidEnumArgumentException("max", (int)max, typeof(DispatcherPriority));
            }
            if(max == DispatcherPriority.Inactive)
            {
                throw new ArgumentException(SR.InvalidPriority, nameof(max));
            }
            
            if (max < min)
            {
                throw new ArgumentException(SR.InvalidPriorityRangeOrder);
            }

            _min = min;
            _isMinInclusive = isMinInclusive;
            _max = max;
            _isMaxInclusive = isMaxInclusive;
        }

        // This is a constructor for our special static members.
        private PriorityRange(DispatcherPriority min, DispatcherPriority max, bool ignored) // NOTE: should be Priority
        {
            _min = min;
            _isMinInclusive = true;
            _max = max;
            _isMaxInclusive = true;
        }

        private DispatcherPriority _min;  // NOTE: should be Priority

View on GitHub (pinned to 81131a70a4)