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

  1. Enable the RepeatButton before invoking (owner.IsEnabled = true)
  2. Guard the call with a check of the peer's IsEnabled() / owner IsEnabled
  3. 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

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


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)