dotnet/wpf · warning · InvalidOperationException

InvalidOperationException

Error message

InvalidOperationException

What it means

PasswordBoxAutomationPeer's IsPassword property getter throws a bare InvalidOperationException when AccessibilitySwitches.UseNetFx47CompatibleAccessibilityFeatures is true. This reproduces the .NET Framework 4.7 behavior where querying IsPassword on the password box peer was not supported and threw, instead of the modern behavior of returning an empty string.

Solutions

  1. Remove or disable the UseNetFx47CompatibleAccessibilityFeatures switch so the modern code path returns an empty string instead of throwing.
  2. Update the UIA client/screen-reader integration to tolerate or skip the IsPassword query on password boxes.
  3. Wrap the property read in try/catch in automation tooling that enumerates all properties.

Example fix

// before (app config enabling legacy accessibility)
bool compat = AccessibilitySwitches.UseNetFx47CompatibleAccessibilityFeatures; // throws on IsPassword read
// after
// remove the switch (registry/app setting) so peers use modern behavior:
// IsPassword getter returns string.Empty instead of throwing
Defensive patterns

Strategy: try-catch

Validate before calling

bool legacy = AccessibilitySwitches.UseNetFx47CompatibleAccessibilityFeatures; // avoid reading IsPassword on the peer when legacy switch is on

Try / catch

try { var p = peer.IsPassword; } catch (InvalidOperationException) { /* legacy 4.7 accessibility mode: treat as unsupported */ }

Prevention

When it happens

Trigger: A UIA client reads the IsPassword automation property while the app runs with UseNetFx47CompatibleAccessibilityFeatures set (registry/config compatibility switch for legacy accessibility), causing the peer to throw instead of returning string.Empty.

Common situations: Apps that enabled the NetFx47 accessibility compatibility switch to work around third-party screen-reader issues; automation logs or UIA inspection tools (Inspect.exe, accessibility verifiers) that probe all properties on every element.

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/98e9af380d05c36d. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/PasswordBoxAutomationPeer.cs:108

            return true;
        }
        
        bool IValueProvider.IsReadOnly
        {
            get
            {
                return false;
            }
        }

        string IValueProvider.Value
        {
            get 
            {
                //  We shouldn't throw InvalidOperationException, return an empty string instead
                if (AccessibilitySwitches.UseNetFx47CompatibleAccessibilityFeatures)
                {
                    throw new InvalidOperationException();
                }
                else
                {
                    return string.Empty;
                }
            }
        }

        void IValueProvider.SetValue(string value)
        {
            if(!IsEnabled())
                throw new ElementNotEnabledException();

            PasswordBox owner = (PasswordBox)Owner;

            ArgumentNullException.ThrowIfNull(value);

            owner.Password = value;

View on GitHub (pinned to 81131a70a4)