dotnet/wpf · error · ElementNotEnabledException
ElementNotEnabledException
Error message
ElementNotEnabledException
What it means
RangeBaseAutomationPeer's IRangeValueProvider.SetValue throws ElementNotEnabledException when the owning control (e.g. Slider, ProgressBar, ScrollBar) is disabled. UIA SetValue requests must not succeed on disabled elements, so the peer explicitly raises this COM-visible UIA exception.
Solutions
- Enable the owner control before setting the value (owner.IsEnabled = true)
- Check owner.IsEnabled before issuing the UIA SetValue call
- Catch ElementNotEnabledException and surface a 'control disabled' message to the user/test
Example fix
// before
((IValueProvider)peer.GetPattern(PatternInterface.RangeValue)).SetValue(50);
// after
if (slider.IsEnabled)
((IRangeValueProvider)peer).SetValue(50);
else
slider.IsEnabled = true; // then set Defensive patterns
Strategy: validation
Validate before calling
if (!rangeBase.IsEnabled) throw/return /* handle disabled */;
Type guard
static bool CanSetValue(RangeBase c) => c?.IsEnabled == true;
Try / catch
try { rangeValueProvider.SetValue(val); }
catch (ElementNotEnabledException) { /* owner disabled; enable or report */ } Prevention
- Check IsEnabled before any UIA pattern call
- Keep track of why controls are disabled in your app state
- Wait-for-enabled in test automation before interacting
- Catch UIA COM exceptions (UIA_E_ELEMENTNOTENABLED) on the client side
When it happens
Trigger: Calling SetValue(double) on the RangeValue pattern when RangeBaseAutomationPeer.IsEnabled() returns false (owner control IsEnabled=false).
Common situations: Test scripts setting a Slider value while the control is disabled; UIA clients driving forms where a field is disabled until validation passes.
Related errors
- ElementNotEnabledException
- ElementNotEnabledException
- ElementNotEnabledException
- ElementNotEnabledException
- ArgumentOutOfRangeException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/dde2cb2b24970b9e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/RangeBaseAutomationPeer.cs:70
internal virtual void SetValueCore(double val)
{
RangeBase owner = (RangeBase)Owner;
ArgumentOutOfRangeException.ThrowIfLessThan(val, owner.Minimum);
ArgumentOutOfRangeException.ThrowIfGreaterThan(val, owner.Maximum);
owner.Value = (double)val;
}
/// <summary>
/// Request to set the value that this UI element is representing
/// </summary>
/// <param name="val">Value to set the UI to, as an object</param>
/// <returns>true if the UI element was successfully set to the specified value</returns>
//[CodeAnalysis("AptcaMethodsShouldOnlyCallAptcaMethods")] //Tracking Bug: 29647
void IRangeValueProvider.SetValue(double val)
{
if (!IsEnabled())
throw new ElementNotEnabledException();
SetValueCore(val);
}
/// <summary>Value of a value control, as an object</summary>
double IRangeValueProvider.Value
{
get
{
return ((RangeBase)Owner).Value;
}
}
///<summary>Indicates that the value can only be read, not modified.
///returns True if the control is read-only</summary>
bool IRangeValueProvider.IsReadOnly
{View on GitHub (pinned to 81131a70a4)