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

  1. Enable the control before invoking: linkLabel.Enabled = true.
  2. Check the element's IsEnabled property (via AutomationElement) and skip or wait until it is true.
  3. Catch ElementNotEnabledException around Invoke() and retry after enabling.
  4. 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

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


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)