{"record":{"id":"7e0b4e580b233acf","repo":"dotnet/wpf","slug":"invalid-priority-range-order","errorCode":null,"errorMessage":"Invalid priority range order.","messagePattern":"Invalid priority range order\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/PriorityRange.cs","lineNumber":286,"sourceCode":"\n            if (!max.IsValid)\n            {\n                throw new ArgumentException(\"Invalid priority.\", \"max\");\n            }\n            */\n            if(max < DispatcherPriority.Invalid || max > DispatcherPriority.Send)\n            {\n                // If we move to a Priority class, this exception will have to change too.\n                throw new System.ComponentModel.InvalidEnumArgumentException(\"max\", (int)max, typeof(DispatcherPriority));\n            }\n            if(max == DispatcherPriority.Inactive)\n            {\n                throw new ArgumentException(SR.InvalidPriority, nameof(max));\n            }\n            \n            if (max < min)\n            {\n                throw new ArgumentException(SR.InvalidPriorityRangeOrder);\n            }\n\n            _min = min;\n            _isMinInclusive = isMinInclusive;\n            _max = max;\n            _isMaxInclusive = isMaxInclusive;\n        }\n\n        // This is a constructor for our special static members.\n        private PriorityRange(DispatcherPriority min, DispatcherPriority max, bool ignored) // NOTE: should be Priority\n        {\n            _min = min;\n            _isMinInclusive = true;\n            _max = max;\n            _isMaxInclusive = true;\n        }\n\n        private DispatcherPriority _min;  // NOTE: should be Priority","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/PriorityRange.cs#L268-L304","documentation":"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.","triggerScenarios":"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.","commonSituations":"Refactoring that reversed parameter order; assuming enum declaration order equals numeric order; dynamic construction where user input supplies min/max and can be inverted.","solutions":["Order the bounds numerically: min should be the lower numeric value, max the higher (e.g. min: Background/4, max: Send/10).","If the intent is 'from Send down to Normal', use Dispatcher.Unwrapped priority comparisons or iterate the range yourself instead of an inverted PriorityRange.","Normalize inputs before constructing: if (min > max) swap them."],"exampleFix":"// before\nvar range = new PriorityRange(DispatcherPriority.Send, true, DispatcherPriority.Background, true);\n// after\nvar range = new PriorityRange(DispatcherPriority.Background, true, DispatcherPriority.Send, true);","handlingStrategy":"validation","validationCode":"if (min > max)\n    (min, max) = (max, min); // normalize before constructing the range","typeGuard":"static bool IsOrderedRange(DispatcherPriority min, DispatcherPriority max) => min <= max;","tryCatchPattern":"try\n{\n    var range = new PriorityRange(min, true, max, true);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"range order\"))\n{\n    logger.LogError(ex, \"min ({Min}) exceeds max ({Max})\", min, max);\n    throw;\n}","preventionTips":["Remember numeric order: Invalid(-1) < Inactive(0) < SystemIdle < ... < Send(10).","Normalize min/max with a swap before construction when inputs are dynamic.","Add unit tests for range construction with user-supplied bounds."],"tags":["wpf","dispatcher","priority","argument-order"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}