dotnet/wpf · error · ArgumentException
Invalid priority value.
Error message
Invalid priority value.
What it means
Dispatcher.LegacyInvokeImpl (the implementation behind legacy Dispatcher.Invoke(DispatcherPriority, Delegate, ...) calls) throws ArgumentException with SR.InvalidPriority when the priority is DispatcherPriority.Inactive. After ValidatePriority confirms the value is a real DispatcherPriority, Inactive is additionally banned because items queued as Inactive are never processed — an active invocation must use a processable priority.
Solutions
- Pass a processable priority such as DispatcherPriority.Normal or Background instead of Inactive.
- Guard: if (priority == DispatcherPriority.Inactive) priority = DispatcherPriority.Normal;
- Fix uninitialized/default DispatcherPriority variables.
- Use InvokeAsync with an explicit valid priority for modern call paths.
Example fix
// before dispatcher.Invoke(callback, DispatcherPriority.Inactive); // after dispatcher.Invoke(callback, DispatcherPriority.Normal);
Defensive patterns
Strategy: validation
Validate before calling
if (priority == DispatcherPriority.Inactive)
priority = DispatcherPriority.Normal;
dispatcher.Invoke(callback, priority); Prevention
- Never queue active work at DispatcherPriority.Inactive (it never runs)
- Initialize DispatcherPriority fields explicitly; the default is Inactive
- Assign a fallback priority when one is computed dynamically
- Prefer InvokeAsync with an explicit priority over legacy Delegate-based Invoke
When it happens
Trigger: Calling dispatcher.Invoke(action, DispatcherPriority.Inactive, ...) or any legacy Invoke/BeginInvoke path with priority Inactive; passing a priority variable that defaulted to Inactive (its numeric default is a valid enum value).
Common situations: A DispatcherPriority field left uninitialized (default(Inactive)); code that queues work conditionally and falls through with Inactive; UI framework internals where an inactive queued item's priority was reused for a synchronous call.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- The value of argument 'parameterName' (priority) is invalid…
- Invalid priority range order.
- Invalid priority value.
- ElementNotAvailableException
- FileAccess value is not valid.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/1e490cd60d2e54e4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs:1249
/// <param name="args">
/// An array of objects to pass as arguments to the given method.
/// This can be null if no arguments are needed.
/// </param>
/// <returns>
/// The return value from the delegate being invoked, or null if
/// the delegate has no return value.
/// </returns>
public object Invoke(Delegate method, TimeSpan timeout, DispatcherPriority priority, params object[] args)
{
return LegacyInvokeImpl(priority, timeout, method, args, -1);
}
internal object LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, object args, int numArgs)
{
ValidatePriority(priority, "priority");
if(priority == DispatcherPriority.Inactive)
{
throw new ArgumentException(SR.InvalidPriority, nameof(priority));
}
ArgumentNullException.ThrowIfNull(method);
if ( timeout.TotalMilliseconds < 0 &&
timeout != TimeSpan.FromMilliseconds(-1))
{
if(CheckAccess())
{
// Application Compat
// In versions before 4.5, when invoking on the same
// thread, any negative timeout was effectively an
// infinite wait. When invoking across threads, any
// negative timeout other than -1ms was an error which
// threw an exception internally when waiting on an event.
timeout = TimeSpan.FromMilliseconds(-1);
}
elseView on GitHub (pinned to 81131a70a4)