{"record":{"id":"e50fb1ee550f4ca9","repo":"dotnet/wpf","slug":"sr-operationcannotbeperformed-windowssysheader","errorCode":null,"errorMessage":"SR.OperationCannotBePerformed","messagePattern":"SR\\.OperationCannotBePerformed","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSysHeader.cs","lineNumber":475,"sourceCode":"            #region Invoke Pattern\n\n            // Same as a click on one of the header element\n            void IInvokeProvider.Invoke ()\n            {\n                // Make sure that the control is enabled\n                if (!SafeNativeMethods.IsWindowEnabled(_hwnd))\n                {\n                    throw new ElementNotEnabledException();\n                }\n\n                WindowsSysHeader parent = _parent as WindowsSysHeader;\n                parent?.ScrollIntoView(this);\n\n                NativeMethods.Win32Point pt;\n\n                if (!GetInvokationPoint (out pt))\n                {\n                    throw new InvalidOperationException(SR.OperationCannotBePerformed);\n                }\n\n                IntPtr center = NativeMethods.Util.MAKELPARAM (pt.x, pt.y);\n\n                // click\n                Misc.ProxySendMessage(_hwnd, NativeMethods.WM_LBUTTONDOWN, new IntPtr(NativeMethods.MK_LBUTTON), center);\n                Misc.ProxySendMessage(_hwnd, NativeMethods.WM_LBUTTONUP, IntPtr.Zero, center);\n            }\n\n            #endregion Invoke Pattern\n            #region ExpandCollapse Pattern\n\n            void IExpandCollapseProvider.Expand ()\n            {\n                if (!IsExpanded())\n                {\n                    ClickSplitButton();\n                }","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSysHeader.cs#L457-L493","documentation":"WindowsSysHeader's Invoke pattern implementation clicks the header item by simulating WM_LBUTTONDOWN/UP at the item's on-screen center. GetInvokationPoint computes that point; when it fails (e.g. the item cannot be located on screen), Invoke throws InvalidOperationException with SR.OperationCannotBePerformed.","triggerScenarios":"Calling IInvokeProvider.Invoke on a header control item whose screen coordinates cannot be obtained (item scrolled out of view, parent unavailable, or the window is minimized/hidden).","commonSituations":"Clicking column headers of a listview that is minimized or on an invisible virtual desktop; header items scrolled horizontally out of the visible area; automation running in a hidden session (e.g. CI service without interactive desktop).","solutions":["Ensure the header's parent window is visible and restored (not minimized) before Invoke.","Scroll the header/item into view before invoking; the proxy already attempts parent ScrollIntoView but it can fail for hidden windows.","Run automation in an interactive desktop session instead of a headless service context."],"exampleFix":"// before\ninvokePattern.Invoke();\n// after\nif (window.WindowPattern.Current.WindowVisualState != WindowVisualState.Normal)\n    windowPattern.ShowWindow(WindowVisualState.Normal);\ninvokePattern.Invoke();","handlingStrategy":"try-catch","validationCode":"if (!headerElement.Current.IsOffscreen && windowVisualState != WindowVisualState.Minimized) invokePattern.Invoke();","typeGuard":"static bool IsInvokableOnScreen(AutomationElement e) => !e.Current.IsOffscreen && e.Current.IsEnabled;","tryCatchPattern":"try { invokePattern.Invoke(); }\ncatch (InvalidOperationException) { /* item not on screen / window hidden; restore and retry */ }","preventionTips":["Restore minimized windows before automation","Check IsOffscreen before Invoke","Run in an interactive desktop session"],"tags":["uiautomation","invoke","window-state"],"backgroundTag":"unsupported-operation","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"}