{"record":{"id":"76f1a1c45994d002","repo":"dotnet/wpf","slug":"elementnotenabledexception-passwordboxautomationpeer","errorCode":null,"errorMessage":"ElementNotEnabledException","messagePattern":"ElementNotEnabledException","errorType":"exception","errorClass":"ElementNotEnabledException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/PasswordBoxAutomationPeer.cs","lineNumber":120,"sourceCode":"        {\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;\n        }\n\n        // BUG 1555137: Never inline, as we don't want to unnecessarily link the automation DLL\n        [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]\n        internal void RaiseValuePropertyChangedEvent(string oldValue, string newValue)\n        {\n            if (oldValue != newValue)\n            {\n                RaisePropertyChangedEvent(ValuePatternIdentifiers.ValueProperty, oldValue, newValue);\n            }\n        }\n","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/PasswordBoxAutomationPeer.cs#L102-L138","documentation":"IValueProvider.SetValue on PasswordBoxAutomationPeer throws ElementNotEnabledException when the owner PasswordBox is disabled (IsEnabled() is false). The Value pattern refuses programmatic text changes on non-enabled controls.","triggerScenarios":"A UIA client calls ValuePattern.SetValue(value) on a disabled PasswordBox, or calls it before the control is enabled during startup/login flows; also thrown if SetValue is called with a null value? No — null hits ArgumentNullException separately.","commonSituations":"Test automation filling login dialogs before the password box is enabled; apps that disable the password field until a username is valid or during authentication-in-progress.","solutions":["Enable the PasswordBox before setting the value (fix the disabling condition in the app UI/logic).","In the UIA client, check ValuePattern or element.IsEnabled before calling SetValue and wait until it is enabled.","Catch ElementNotEnabledException and retry after the UI reaches the enabled state."],"exampleFix":"// before\nvaluePattern.SetValue(password);\n// after\nif (passwordBox.IsEnabled)\n{\n    passwordBox.Password = password;\n}","handlingStrategy":"try-catch","validationCode":"if (!passwordBox.IsEnabled) { /* wait or enable before setting the password */ }","typeGuard":null,"tryCatchPattern":"try { valuePattern.SetValue(value); } catch (ElementNotEnabledException) { /* retry after control is enabled */ }","preventionTips":["Check IsEnabled/ValuePattern availability before SetValue","Ensure login flows enable fields before automation fills them","Use retry-with-timeout around UIA value writes"],"tags":["wpf","uiautomation","passwordbox","disabled-element"],"backgroundTag":"feature-not-enabled","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"}