dotnet/wpf · error · ElementNotEnabledException
new ElementNotEnabledException()
Error message
new ElementNotEnabledException()
What it means
RangeValuePattern.SetValue first checks the element's IsEnabled property; if the element reports disabled, it throws ElementNotEnabledException. The pattern deliberately tests Enabled before the more general read-only check so callers get the most specific error.
Solutions
- Before SetValue, read AutomationElement.IsEnabledProperty (or TryGetCurrentPropertyValue) and skip/enable the control first
- Wait for the element to become enabled (poll or automation event on IsEnabledProperty/property-changed events)
- Catch ElementNotEnabledException around SetValue and surface a clear failure to the test/user
- Re-acquire the pattern/element; stale cached state can report incorrect enabled values
Example fix
// before
rangePattern.SetValue(10); // ElementNotEnabledException if disabled
// after
if (element.TryGetCurrentPropertyValue(AutomationElement.IsEnabledProperty, out var enabled) && (bool)enabled)
{
rangePattern.SetValue(10);
} Defensive patterns
Strategy: try-catch
Validate before calling
bool isEnabled = element.TryGetCurrentPropertyValue(AutomationElement.IsEnabledProperty, out var en) && en is bool b && b; if (!isEnabled) return; // skip or wait until enabled
Type guard
bool IsEnabled(AutomationElement e) => e.TryGetCurrentPropertyValue(AutomationElement.IsEnabledProperty, out var v) && v is bool b && b;
Try / catch
try { rangePattern.SetValue(value); } catch (ElementNotEnabledException) { /* wait for enablement or abort step */ } Prevention
- Check IsEnabledProperty before SetValue
- Subscribe to property-changed events to wait for enablement
- Re-acquire patterns after UI state changes
- Handle disabled controls explicitly in test automation flows
When it happens
Trigger: Calling SetValue on a RangeValuePattern whose automation element is disabled (IsEnabledProperty false): e.g. a slider/spinner disabled in the UI, a window disabled/modally blocked, or an invalid-state control.
Common situations: Automating UI where the target control is disabled until a preceding step completes; test automation racing with app initialization; interacting with controls in disabled dialogs.
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
- new ElementNotEnabledException()
- Element is not enabled.
- Element is not enabled.
- ElementNotEnabledException
- ElementNotEnabledException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/6c59a5946f34360e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/RangeValuePattern.cs:91
//------------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------
#region Public Methods
/// <summary>
/// Request to set the value that this UI element is representing
/// </summary>
/// <param name="value">Value to set the UI to, as a double</param>
public void SetValue(double value)
{
// Test the Enabled state prior to the more general Read-Only state.
object enabled = _el.GetCurrentPropertyValue(AutomationElementIdentifiers.IsEnabledProperty);
if (enabled is bool && !(bool)enabled)
{
throw new ElementNotEnabledException();
}
// Test the Read-Only state after the more specific Enabled state.
object readOnly = _el.GetCurrentPropertyValue(IsReadOnlyProperty);
if (readOnly is bool && (bool)readOnly)
{
throw new InvalidOperationException(SR.ValueReadonly);
}
UiaCoreApi.RangeValuePattern_SetValue(_hPattern, value);
}
#endregion Public Methods
//------------------------------------------------------
//
// Public Properties
//View on GitHub (pinned to 81131a70a4)