{"record":{"id":"98e9af380d05c36d","repo":"dotnet/wpf","slug":"invalidoperationexception-passwordboxautomationpeer","errorCode":null,"errorMessage":"InvalidOperationException","messagePattern":"InvalidOperationException","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"warning","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/PasswordBoxAutomationPeer.cs","lineNumber":108,"sourceCode":"            return true;\n        }\n        \n        bool IValueProvider.IsReadOnly\n        {\n            get\n            {\n                return false;\n            }\n        }\n\n        string IValueProvider.Value\n        {\n            get \n            {\n                //  We shouldn't throw InvalidOperationException, return an empty string instead\n                if (AccessibilitySwitches.UseNetFx47CompatibleAccessibilityFeatures)\n                {\n                    throw new InvalidOperationException();\n                }\n                else\n                {\n                    return string.Empty;\n                }\n            }\n        }\n\n        void IValueProvider.SetValue(string value)\n        {\n            if(!IsEnabled())\n                throw new ElementNotEnabledException();\n\n            PasswordBox owner = (PasswordBox)Owner;\n\n            ArgumentNullException.ThrowIfNull(value);\n\n            owner.Password = value;","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/PasswordBoxAutomationPeer.cs#L90-L126","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove or disable the UseNetFx47CompatibleAccessibilityFeatures switch so the modern code path returns an empty string instead of throwing.","Update the UIA client/screen-reader integration to tolerate or skip the IsPassword query on password boxes.","Wrap the property read in try/catch in automation tooling that enumerates all properties."],"exampleFix":"// before (app config enabling legacy accessibility)\nbool compat = AccessibilitySwitches.UseNetFx47CompatibleAccessibilityFeatures; // throws on IsPassword read\n// after\n// remove the switch (registry/app setting) so peers use modern behavior:\n// IsPassword getter returns string.Empty instead of throwing","handlingStrategy":"try-catch","validationCode":"bool legacy = AccessibilitySwitches.UseNetFx47CompatibleAccessibilityFeatures; // avoid reading IsPassword on the peer when legacy switch is on","typeGuard":null,"tryCatchPattern":"try { var p = peer.IsPassword; } catch (InvalidOperationException) { /* legacy 4.7 accessibility mode: treat as unsupported */ }","preventionTips":["Avoid enabling UseNetFx47CompatibleAccessibilityFeatures unless required by legacy screen readers","Configure automation inspection tools to skip IsPassword on password fields","Centralize property reads so one try/catch covers legacy-mode throws"],"tags":["wpf","uiautomation","passwordbox","accessibility-compat-switch"],"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"}