{"record":{"id":"f0dbbfbb2a9a4596","repo":"dotnet/wpf","slug":"sr-notallowedtoaccessstagingarea","errorCode":null,"errorMessage":"SR.NotAllowedToAccessStagingArea","messagePattern":"SR\\.NotAllowedToAccessStagingArea","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ProcessInputEventArgs.cs","lineNumber":50,"sourceCode":"        /// <summary>\n        ///     Pushes an input event onto the top of the staging area.\n        /// </summary>\n        /// <param name=\"input\">\n        ///     The input event to place on the staging area.  This may not\n        ///     be null, and may not already exist in the staging area.\n        /// </param>\n        /// <param name=\"promote\">\n        ///     An existing staging area item to promote the state from.\n        /// </param>\n        /// <returns>\n        ///     The staging area input item that wraps the specified input.\n        /// </returns>\n        public StagingAreaInputItem PushInput(InputEventArgs input, \n                                              StagingAreaInputItem promote) // Note: this should be a bool, and always use the InputItem available on these args.\n        {\n            if(!_allowAccessToStagingArea)\n            {\n                throw new InvalidOperationException(SR.NotAllowedToAccessStagingArea);\n            }\n            \n            return this.UnsecureInputManager.PushInput(input, promote);\n        }\n\n        /// <summary>\n        ///     Pushes an input event onto the top of the staging area.\n        /// </summary>\n        /// <param name=\"input\">\n        ///     The input event to place on the staging area.  This may not\n        ///     be null, and may not already exist in the staging area.\n        /// </param>\n        /// <returns>\n        ///     The specified staging area input item.\n        /// </returns>      \n        public StagingAreaInputItem PushInput(StagingAreaInputItem input)\n        {\n            if(!_allowAccessToStagingArea)","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ProcessInputEventArgs.cs#L32-L68","documentation":"ProcessInputEventArgs.PushInput(InputEventArgs, StagingAreaInputItem) throws InvalidOperationException when the input staging area is not currently accessible. WPF only allows staging-area manipulation from inside an input event handler (e.g. PreProcessInput/PreNotifyInput/PostProcessInput) that is running on the thread's InputManager. Outside that window _allowAccessToStagingArea is false and the call is rejected.","triggerScenarios":"Calling PushInput on a ProcessInputEventArgs instance outside a PreProcessInput/PreNotifyInput/PostProcessInput event handler, from a different thread than the input manager's dispatcher, or after the handler's event dispatch has completed (e.g. stashing the args object and using it later).","commonSituations":"Developers cache ProcessInputEventArgs from an InputManager event and reuse it asynchronously (Dispatcher.BeginInvoke), or call PushInput from a background thread, or attempt staging-area mutation from an unrelated event like a timer tick.","solutions":["Move the PushInput call inside the PreProcessInput/PostProcessInput handler where the args were delivered.","Never cache ProcessInputEventArgs; perform all staging-area work synchronously within the handler.","If you must defer work, capture the InputEventArgs payload instead and re-post input via InputManager.Current.ProcessInput on the dispatcher thread.","Ensure the code runs on the same thread as the InputManager's dispatcher."],"exampleFix":"// before\nvoid OnPostProcessInput(object sender, ProcessInputEventArgs e)\n{\n    Dispatcher.BeginInvoke(() => e.PushInput(myInput, null)); // throws\n}\n\n// after\nvoid OnPostProcessInput(object sender, ProcessInputEventArgs e)\n{\n    e.PushInput(myInput, null); // do it synchronously inside the handler\n}","handlingStrategy":"validation","validationCode":"// Only call inside PreProcessInput/PreNotifyInput/PostProcessInput handlers.\nvoid OnPostProcessInput(object sender, ProcessInputEventArgs e)\n{\n    e.PushInput(newInput, null); // safe: inside handler\n}","typeGuard":"bool CanUseStagingArea(ProcessInputEventArgs e, out bool allowed)\n{\n    // Access is granted only during input-event dispatch; there is no public\n    // flag, so enforce it structurally: only call from within the handler.\n    allowed = IsInsideInputEventHandler();\n    return allowed;\n}","tryCatchPattern":"try\n{\n    e.PushInput(input, promote);\n}\ncatch (InvalidOperationException ex)\n{\n    // not in an input handler; defer via InputManager.Current.ProcessInput\n    Log(ex);\n}","preventionTips":["Never store ProcessInputEventArgs beyond the handler invocation.","Keep all staging-area manipulation synchronous inside input handlers.","Stay on the InputManager's dispatcher thread.","Prefer preview events or InputManager.ProcessInput for deferred input work."],"tags":["wpf","input","invalid-operation","threading"],"backgroundTag":"unsupported-operation","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"}