{"record":{"id":"1e490cd60d2e54e4","repo":"dotnet/wpf","slug":"invalid-priority-value","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/Dispatcher.cs","lineNumber":1249,"sourceCode":"        /// <param name=\"args\">\n        ///     An array of objects to pass as arguments to the given method.\n        ///     This can be null if no arguments are needed.\n        /// </param>\n        /// <returns>\n        ///     The return value from the delegate being invoked, or null if\n        ///     the delegate has no return value.\n        /// </returns>\n        public object Invoke(Delegate method, TimeSpan timeout, DispatcherPriority priority, params object[] args)\n        {\n            return LegacyInvokeImpl(priority, timeout, method, args, -1);\n        }\n\n        internal object LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, object args, int numArgs)\n        {\n            ValidatePriority(priority, \"priority\");\n            if(priority == DispatcherPriority.Inactive)\n            {\n                throw new ArgumentException(SR.InvalidPriority, nameof(priority));\n            }\n\n            ArgumentNullException.ThrowIfNull(method);\n\n            if ( timeout.TotalMilliseconds < 0 &&\n                timeout != TimeSpan.FromMilliseconds(-1))\n            {\n                if(CheckAccess())\n                {\n                    // Application Compat\n                    // In versions before 4.5, when invoking on the same\n                    // thread, any negative timeout was effectively an\n                    // infinite wait.  When invoking across threads, any\n                    // negative timeout other than -1ms was an error which\n                    // threw an exception internally when waiting on an event.\n                    timeout = TimeSpan.FromMilliseconds(-1);\n                }\n                else","sourceCodeStart":1231,"sourceCodeEnd":1267,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs#L1231-L1267","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\ndispatcher.Invoke(callback, DispatcherPriority.Inactive);\n// after\ndispatcher.Invoke(callback, DispatcherPriority.Normal);","handlingStrategy":"validation","validationCode":"if (priority == DispatcherPriority.Inactive)\n    priority = DispatcherPriority.Normal;\ndispatcher.Invoke(callback, priority);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["wpf","dispatcher","priority","invalid-enum"],"backgroundTag":"invalid-enum-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"}