dotnet/wpf · error · ElementNotEnabledException
Element is not enabled.
Error message
Element is not enabled.
What it means
WindowsFormsLinkLabel's Invoke pattern first verifies the underlying Win32 control is enabled via IsWindowEnabled; if not, it throws ElementNotEnabledException to comply with the UIA Invoke pattern contract.
Solutions
- Enable the control before invoking: linkLabel.Enabled = true.
- Check the element's IsEnabled property (via AutomationElement) and skip or wait until it is true.
- Catch ElementNotEnabledException around Invoke() and retry after enabling.
- If the control is disabled because a parent container is disabled, enable the container first.
Example fix
// before
invokePattern.Invoke();
// after
if (element.Current.IsEnabled)
{
invokePattern.Invoke();
}
else
{
// enable or wait
} Defensive patterns
Strategy: try-catch
Validate before calling
bool canInvoke = element.Current.IsEnabled;
if (!canInvoke) { /* enable via app state or abort */ } Type guard
static bool IsInvokable(AutomationElement e) => (bool)e.GetCurrentValue(InvokePattern.IsEnabledProperty) && e.TryGetCurrentPattern(InvokePattern.Pattern, out _);
Try / catch
try { invokePattern.Invoke(); }
catch (ElementNotEnabledException) { /* enable control or surface state error */ } Prevention
- Check AutomationElement.IsEnabledProperty before Invoke
- Wait for the enabling condition rather than invoking immediately
- Ensure parent containers are not disabling the control
- Design automation flows to include state-assertion steps
When it happens
Trigger: Calling Invoke() on a LinkLabel automation element while the control's Enabled property is false (control disabled in code, designer, or because its container is disabled).
Common situations: Forms with disabled controls pending validation or prerequisite state; automation scripts running before the form finishes enabling controls; disabled LinkLabels used as visual placeholders.
Related errors
- Element is not enabled.
- Operation cannot be performed.
- ' ' is not a valid value for this control.
- Element is not enabled.
- Element is not enabled.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/06c56a99603586e3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsFormsLinkLabel.cs:110
return true;
}
#endregion ProxySimple Interface
#region Invoke Pattern
// Same as clicking on an hyperlink
void IInvokeProvider.Invoke()
{
// Check that button can be clicked.
//
// This state could change anytime.
//
// Make sure that the control is enabled
if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
{
throw new ElementNotEnabledException();
}
if (!SafeNativeMethods.IsWindowVisible(_hwnd))
{
throw new InvalidOperationException(SR.OperationCannotBePerformed);
}
Misc.SetFocus(_hwnd);
NativeMethods.Win32Point pt = new NativeMethods.Win32Point();
if (GetClickablePoint(out pt, false))
{
Misc.MouseClick(pt.x, pt.y);
}
}
#endregion Invoke Pattern
}View on GitHub (pinned to 81131a70a4)