dotnet/wpf · info · InvalidOperationException

SR.UIA_OperationCannotBePerformed

Error message

SR.UIA_OperationCannotBePerformed

What it means

GridViewColumnHeaderAutomationPeer implements ITransformProvider.Move by unconditionally throwing InvalidOperationException(SR.UIA_OperationCannotBePerformed). The WPF ListView/GridView column header does not support being moved via UI Automation, so the pattern advertises CanMove=false and any Move call fails. This is a deliberate 'operation not supported' contract, not a bug in the caller's code.

Solutions

  1. Do not call Move on GridViewColumnHeader peers; check ITransformProvider.CanMove (returns false) before invoking Move.
  2. Reorder columns via supported APIs instead: set GridViewColumnCollection index / GridViewColumn.Header, or simulate header drag through mouse-level automation.
  3. Wrap the call in try-catch for InvalidOperationException and fall back to a different reorder mechanism if a generic automation driver always calls Move.

Example fix

// before
transformPattern.Move(100, 0); // reorder column by moving header
// after
if (transformPatternCached.CanMove)
{
    transformPattern.Move(100, 0);
}
else
{
    // reorder via GridViewColumnCollection instead
    gridView.Columns.Move(oldIndex, newIndex);
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!transformPatternCached.CanMove) throwSkipOrFallback();

Type guard

bool CanMove(ITransformProvider t) => t is { CanMove: true };

Try / catch

try { transformPattern.Move(x, y); } catch (InvalidOperationException) { /* reorder via GridViewColumnCollection */ }

Prevention

When it happens

Trigger: Calling ITransformProvider.Move(x, y) on the automation peer of a GridViewColumnHeader (e.g. via UIA clients using the Transform pattern: Move() in a UIA test, or automation frameworks that call the Transform pattern on header elements).

Common situations: UI Automation tests or RPA scripts attempting to reorder ListView columns by moving the header element; accessibility tools exposing move gestures on column headers.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/cbe496b39b835372. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/GridViewColumnHeaderAutomationPeer.cs:71

                throw new ElementNotEnabledException();

            GridViewColumnHeader owner = (GridViewColumnHeader)Owner;
            owner.AutomationClick();
        }

        #region ITransformProvider

        bool ITransformProvider.CanMove { get { return false; } }

        //Note: CanResize can be false if Max/MinWidth,Height has been added on GridViewColumn/ColumnHeader
        bool ITransformProvider.CanResize { get { return true; } }
        bool ITransformProvider.CanRotate { get { return false; } }

        //Note: Don't support Move so far, if users do need this feature to reorder columns, 
        //we can consider to add it later. (One concern is GVCH doesn't support reorder by moving itself)
        void ITransformProvider.Move(double x, double y)
        {
            throw new InvalidOperationException(SR.UIA_OperationCannotBePerformed);
        }

        void ITransformProvider.Resize(double width, double height)
        {
            if (!IsEnabled())
                throw new ElementNotEnabledException();

            ArgumentOutOfRangeException.ThrowIfNegative(width);
            ArgumentOutOfRangeException.ThrowIfNegative(height);

            GridViewColumnHeader header = Owner as GridViewColumnHeader;
            if (header != null)
            {
                header.Column?.Width = width;

                header.Height = height;
            }
        }

View on GitHub (pinned to 81131a70a4)