dotnet/wpf · error · ElementNotEnabledException
ElementNotEnabledException
Error message
ElementNotEnabledException
What it means
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.
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.
Example fix
// before
valuePattern.SetValue(password);
// after
if (passwordBox.IsEnabled)
{
passwordBox.Password = password;
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!passwordBox.IsEnabled) { /* wait or enable before setting the password */ } Try / catch
try { valuePattern.SetValue(value); } catch (ElementNotEnabledException) { /* retry after control is enabled */ } Prevention
- Check IsEnabled/ValuePattern availability before SetValue
- Ensure login flows enable fields before automation fills them
- Use retry-with-timeout around UIA value writes
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ElementNotEnabledException
- InvalidOperationException
- UIA_E_ELEMENTNOTENABLED
- Decorator marked as PART_ContentHost must have no content.
- E_ACCESSDENIED
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/76f1a1c45994d002.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/PasswordBoxAutomationPeer.cs:120
{
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;
}
// BUG 1555137: Never inline, as we don't want to unnecessarily link the automation DLL
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
internal void RaiseValuePropertyChangedEvent(string oldValue, string newValue)
{
if (oldValue != newValue)
{
RaisePropertyChangedEvent(ValuePatternIdentifiers.ValueProperty, oldValue, newValue);
}
}
View on GitHub (pinned to 81131a70a4)