dotnet/wpf · error · ElementNotEnabledException
ElementNotEnabledException
Error message
ElementNotEnabledException
What it means
RepeatButtonAutomationPeer's IInvokeProvider.Invoke throws ElementNotEnabledException when the RepeatButton is disabled. The UIA Invoke pattern requires the element to be enabled; invoking a disabled button is rejected with this UIA-standard exception.
Solutions
- Enable the RepeatButton before invoking (owner.IsEnabled = true)
- Guard the call with a check of the peer's IsEnabled() / owner IsEnabled
- Catch ElementNotEnabledException and retry after the control becomes enabled
Example fix
// before
((IInvokeProvider)repeatButtonPeer).Invoke();
// after
if (repeatButton.IsEnabled)
((IInvokeProvider)repeatButtonPeer).Invoke(); Defensive patterns
Strategy: validation
Validate before calling
if (!repeatButton.IsEnabled) { /* enable or abort */ } Type guard
static bool CanInvoke(ButtonBase b) => b?.IsEnabled == true;
Try / catch
try { invokeProvider.Invoke(); }
catch (ElementNotEnabledException) { /* control disabled */ } Prevention
- Check IsEnabled before Invoke
- Avoid invoking buttons disabled by in-flight operations
- Poll for IsEnabled in UI tests
- Handle UIA_E_ELEMENTNOTENABLED HRESULT in clients
When it happens
Trigger: Calling Invoke() on the Invoke pattern of a RepeatButton with IsEnabled=false.
Common situations: Automation tests clicking a disabled button (e.g. during a long-running operation that disables UI); accessibility clients activating a disabled repeat control.
Related errors
- ElementNotEnabledException
- ElementNotEnabledException
- ElementNotEnabledException
- ElementNotEnabledException
- ArgumentOutOfRangeException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/e1e22229ea66120f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/RepeatButtonAutomationPeer.cs:44
}
///
public override object GetPattern(PatternInterface patternInterface)
{
if (patternInterface == PatternInterface.Invoke)
{
return this;
}
else
{
return base.GetPattern(patternInterface);
}
}
void IInvokeProvider.Invoke()
{
if(!IsEnabled())
throw new ElementNotEnabledException();
RepeatButton owner = (RepeatButton)Owner;
owner.AutomationButtonBaseClick();
}
}
}
View on GitHub (pinned to 81131a70a4)