{"record":{"id":"7f16a61480256025","repo":"dotnet/wpf","slug":"invalid-priority-value-priorityrange","errorCode":null,"errorMessage":"Invalid priority value.","messagePattern":"Invalid priority value\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/PriorityRange.cs","lineNumber":260,"sourceCode":"            /*\n            if(min == null)\n            {\n                throw new ArgumentNullException(\"min\");\n            }\n            \n            if (!min.IsValid)\n            {\n                throw new ArgumentException(\"Invalid priority.\", \"min\");\n            }\n            */\n            if(min < DispatcherPriority.Invalid || min > DispatcherPriority.Send)\n            {\n                // If we move to a Priority class, this exception will have to change too.\n                throw new System.ComponentModel.InvalidEnumArgumentException(\"min\", (int)min, typeof(DispatcherPriority));\n            }\n            if(min == DispatcherPriority.Inactive)\n            {\n                throw new ArgumentException(SR.InvalidPriority, nameof(min));\n            }\n\n            /*            \n            if(max == null)\n            {\n                throw new ArgumentNullException(\"max\");\n            }\n\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            }","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/PriorityRange.cs#L242-L278","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar range = new PriorityRange(DispatcherPriority.Inactive, true, DispatcherPriority.Send, true);\n// after\nvar range = new PriorityRange(DispatcherPriority.Background, true, DispatcherPriority.Send, true);","handlingStrategy":"validation","validationCode":"if (min == DispatcherPriority.Inactive)\n    throw new ArgumentException(\"Use a dispatchable priority as the range minimum; Inactive is a sentinel.\", nameof(min));","typeGuard":"static bool IsDispatchablePriority(DispatcherPriority p) =>\n    p >= DispatcherPriority.SystemIdle && p <= DispatcherPriority.Send;","tryCatchPattern":"try\n{\n    var range = new PriorityRange(min, true, max, true);\n}\ncatch (ArgumentException ex) when (ex.ParamName == nameof(min))\n{\n    logger.LogWarning(\"Inactive min priority rejected; using DispatcherPriority.Background\");\n    var range = new PriorityRange(DispatcherPriority.Background, true, max, true);\n}","preventionTips":["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."],"tags":["wpf","dispatcher","priority","argument"],"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-22T01:17:13.364Z"}