dotnet/wpf · error · InvalidOperationException

SR.OperationCannotBePerformed

Error message

SR.OperationCannotBePerformed

What it means

The status bar proxy exposes the Value pattern as read-only: IValueProvider.SetValue always throws InvalidOperationException with SR.OperationCannotBePerformed. Status bar text is owned by the application, so the automation proxy refuses writes to it.

Solutions

  1. Do not call SetValue on status bar elements; treat them as read-only and verify their Value instead.
  2. Restrict SetValue calls to elements where IValueProvider.IsReadOnly is false.
  3. If the text must change, drive the owning application's API/UI, not the pattern.

Example fix

// before
valuePattern.SetValue("Done");
// after
if (!valuePattern.Current.IsReadOnly) valuePattern.SetValue("Done");
Defensive patterns

Strategy: validation

Validate before calling

var vp = element.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
if (vp != null && !vp.Current.IsReadOnly) { vp.SetValue(text); }

Type guard

static bool IsWritableValue(AutomationElement e) { var v = e.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern; return v != null && !v.Current.IsReadOnly; }

Try / catch

try { vp.SetValue(text); }
catch (InvalidOperationException) { /* element is read-only */ }

Prevention

When it happens

Trigger: Calling IValueProvider.SetValue(string) on a Win32 status bar element obtained via UIA.

Common situations: Test scripts that attempt to set text on every Value-pattern-capable control generically; confusing a status bar with an editable text field; trying to 'fix' displayed status text during automation runs.

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/15ef224c1354e5a6. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsStatusBar.cs:524

            }

            IRawElementProviderSimple IGridItemProvider.ContainingGrid
            {
                get
                {
                    return _parent;
                }
            }

            #endregion Grid Pattern

            #region Value Pattern

            // Sets the text of the edit.
            void IValueProvider.SetValue(string str)
            {
                // This is a read only element.
                throw new InvalidOperationException(SR.OperationCannotBePerformed);
            }

            // Request to get the value that this UI element is representing as a string
            string IValueProvider.Value
            {
                get
                {
                    return Text;
                }
            }

            // Read only status
            bool IValueProvider.IsReadOnly
            {
                get
                {
                    return true;
                }

View on GitHub (pinned to 81131a70a4)