dotnet/wpf · error · InvalidOperationException
SR.OperationCannotBePerformed
Error message
SR.OperationCannotBePerformed
What it means
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.
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.
Example fix
// before
invokePattern.Invoke();
// after
if (window.WindowPattern.Current.WindowVisualState != WindowVisualState.Normal)
windowPattern.ShowWindow(WindowVisualState.Normal);
invokePattern.Invoke(); Defensive patterns
Strategy: try-catch
Validate before calling
if (!headerElement.Current.IsOffscreen && windowVisualState != WindowVisualState.Minimized) invokePattern.Invoke();
Type guard
static bool IsInvokableOnScreen(AutomationElement e) => !e.Current.IsOffscreen && e.Current.IsEnabled;
Try / catch
try { invokePattern.Invoke(); }
catch (InvalidOperationException) { /* item not on screen / window hidden; restore and retry */ } Prevention
- Restore minimized windows before automation
- Check IsOffscreen before Invoke
- Run in an interactive desktop session
When it happens
Trigger: 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).
Common situations: 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).
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Element is not enabled.
- Element is not enabled.
- Operation cannot be performed.
- Operation cannot be performed.
- ' ' is not a valid value for this control.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/e50fb1ee550f4ca9.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsSysHeader.cs:475
#region Invoke Pattern
// Same as a click on one of the header element
void IInvokeProvider.Invoke ()
{
// Make sure that the control is enabled
if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
{
throw new ElementNotEnabledException();
}
WindowsSysHeader parent = _parent as WindowsSysHeader;
parent?.ScrollIntoView(this);
NativeMethods.Win32Point pt;
if (!GetInvokationPoint (out pt))
{
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
IntPtr center = NativeMethods.Util.MAKELPARAM (pt.x, pt.y);
// click
Misc.ProxySendMessage(_hwnd, NativeMethods.WM_LBUTTONDOWN, new IntPtr(NativeMethods.MK_LBUTTON), center);
Misc.ProxySendMessage(_hwnd, NativeMethods.WM_LBUTTONUP, IntPtr.Zero, center);
}
#endregion Invoke Pattern
#region ExpandCollapse Pattern
void IExpandCollapseProvider.Expand ()
{
if (!IsExpanded())
{
ClickSplitButton();
}View on GitHub (pinned to 81131a70a4)