dotnet/wpf · error · ElementNotEnabledException

Element is not enabled.

Error message

Element is not enabled.

What it means

IValueProvider.SetValue on the IP address control proxy first checks that the underlying SysIPAddress32 window is enabled via SafeNativeMethods.IsWindowEnabled. If disabled, it throws ElementNotEnabledException because the control cannot accept input.

Solutions

  1. Enable the control (or its parent) before setting the value
  2. Check UIA's IsEnabled property before calling SetValue and wait until it is true
  3. Catch ElementNotEnabledException and retry once the control is enabled
  4. Fix the application logic that keeps the IP control disabled

Example fix

// before
valuePattern.SetValue("192.168.0.1");
// after
if (ipControl.Current.IsEnabled)
{
    valuePattern.SetValue("192.168.0.1");
}
else
{
    throw new InvalidOperationException("IP control is disabled; enable it before SetValue.");
}
Defensive patterns

Strategy: validation

Validate before calling

if (!ipControl.Current.IsEnabled) throw new InvalidOperationException("IP control disabled; enable before SetValue.");

Try / catch

try { valuePattern.SetValue(val); }
catch (ElementNotEnabledException) { /* wait/enable then retry */ }

Prevention

When it happens

Trigger: Calling IValueProvider.SetValue(string val) on an IP address control whose HWND is disabled (parent dialog disabled it, control grayed out during a long operation).

Common situations: Automating modal dialogs where the IP field is temporarily disabled; disabled controls behind group-box logic; test scripts not accounting for the UI state.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/b91852f6617d3914. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsIPAddress.cs:118

        IRawElementProviderSimple IRawElementProviderHwndOverride.GetOverrideProviderForHwnd (IntPtr hwnd)
        {
            // Find location of passed in hwnd under the parent
            int index = GetIndexOfChildWindow (hwnd);
            System.Diagnostics.Debug.Assert (index != -1, "GetOverrideProviderForHwnd: cannot find child hwnd index");
            return new ByteEditBoxOverride (hwnd, index);
        }

        #endregion IRawElementProviderHwndOverride

        #region Value Pattern

        // Sets the IP Address.
        void IValueProvider.SetValue (string val)
        {
            // Make sure that the control is enabled
            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
            {
                throw new ElementNotEnabledException();
            }

            IPAddress ipAddress = GetIPAddressFromString (val);

            if (ipAddress != null)
            {
                byte[] abOctet = ipAddress.GetAddressBytes();

                if (abOctet.Length == 4)
                {
                    uint ipV4 = 0;

                    for (int iPos = 0; iPos < 4; iPos++)
                    {
                        ipV4 = (ipV4 << 8) + abOctet[iPos];
                    }

                    // no return result for this message, so if it get sent it must have succeeded

View on GitHub (pinned to 81131a70a4)