dotnet/wpf · error · ArgumentException
Invalid priority value.
Error message
Invalid priority value.
What it means
After confirming 'min' is in the numeric enum range, PriorityRange.Initialize additionally rejects DispatcherPriority.Inactive for the lower bound, throwing ArgumentException with SR.InvalidPriority ('Invalid priority value.'). Inactive is a sentinel meaning 'never dispatch', so a range bounded by it would be meaningless for scheduling.
Solutions
- Pass a dispatchable priority (DispatcherPriority.Send up through Send/10, e.g. Background or Normal) as min instead of Inactive.
- Audit where the Inactive value originates — replace default 0 enum values with an explicit valid priority.
- If you genuinely want an empty range, filter priorities before range checks rather than encoding Inactive as a bound.
Example fix
// before var range = new PriorityRange(DispatcherPriority.Inactive, true, DispatcherPriority.Send, true); // after var range = new PriorityRange(DispatcherPriority.Background, true, DispatcherPriority.Send, true);
Defensive patterns
Strategy: validation
Validate before calling
if (min == DispatcherPriority.Inactive)
throw new ArgumentException("Use a dispatchable priority as the range minimum; Inactive is a sentinel.", nameof(min)); Type guard
static bool IsDispatchablePriority(DispatcherPriority p) =>
p >= DispatcherPriority.SystemIdle && p <= DispatcherPriority.Send; Try / catch
try
{
var range = new PriorityRange(min, true, max, true);
}
catch (ArgumentException ex) when (ex.ParamName == nameof(min))
{
logger.LogWarning("Inactive min priority rejected; using DispatcherPriority.Background");
var range = new PriorityRange(DispatcherPriority.Background, true, max, true);
} Prevention
- Never let enum fields default to 0 (Inactive) — initialize them to an explicit valid priority.
- Treat Inactive as a state report, not a range bound.
- Document intended priorities in constants instead of scattered literals.
When it happens
Trigger: Constructing a PriorityRange with min == DispatcherPriority.Inactive, e.g. new PriorityRange(DispatcherPriority.Inactive, true, DispatcherPriority.Send, true) — typically from a default-initialized enum field or persisted value 0 misread as Inactive.
Common situations: Enum fields defaulting to 0 and assumed valid; copying priority values from DispatcherHooks or diagnostics that report Inactive states; hand-rolled scheduler code reusing Inactive as a 'no work' marker.
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
- The value of argument 'parameterName' (priority) is invalid…
- Invalid priority range order.
- Invalid priority value.
- The value of argument 'max' (max) is invalid for Enum type…
- The value of argument 'min' (min) is invalid for Enum type…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/7f16a61480256025.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/PriorityRange.cs:260
/*
if(min == null)
{
throw new ArgumentNullException("min");
}
if (!min.IsValid)
{
throw new ArgumentException("Invalid priority.", "min");
}
*/
if(min < DispatcherPriority.Invalid || min > DispatcherPriority.Send)
{
// If we move to a Priority class, this exception will have to change too.
throw new System.ComponentModel.InvalidEnumArgumentException("min", (int)min, typeof(DispatcherPriority));
}
if(min == DispatcherPriority.Inactive)
{
throw new ArgumentException(SR.InvalidPriority, nameof(min));
}
/*
if(max == null)
{
throw new ArgumentNullException("max");
}
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));
}View on GitHub (pinned to 81131a70a4)