{"record":{"id":"92f662e9274e0178","repo":"dotnet/wpf","slug":"throw-new-elementnotenabledexception","errorCode":null,"errorMessage":"throw new ElementNotEnabledException();","messagePattern":"throw new ElementNotEnabledException\\(\\);","errorType":"exception","errorClass":"ElementNotEnabledException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/UnsupportedAutomationProxies/WindowsDateTimePicker.cs","lineNumber":216,"sourceCode":"                {\n                    return new DateTimeButton (_hwnd, this, (int) DateTimeItem.Button);\n                }\n            }\n\n            return null;\n        }\n\n        #endregion\n\n        #region Value Pattern\n\n        // Sets the text in the edit part of the Combo\n        void IValueProvider.SetValue (string val)\n        {\n            // Make sure that the control is enabled\n            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))\n            {\n                throw new ElementNotEnabledException();\n            }\n\n            if (!SetValue(DateTime.Parse(val, CultureInfo.CurrentCulture)))\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);\n            }\n        }\n\n        // Request to set the value that this UI element is representing as a string\n        string IValueProvider.Value\n        {\n            get\n            {\n                int cLen = Misc.ProxySendMessageInt(_hwnd, NativeMethods.WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero);\n                if (cLen > 0)\n                {\n                    cLen++;\n                    StringBuilder sb = new StringBuilder (cLen);","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/UnsupportedAutomationProxies/WindowsDateTimePicker.cs#L198-L234","documentation":"IValueProvider.SetValue on the DateTimePicker proxy throws ElementNotEnabledException when the Win32 control's HWND is disabled (IsWindowEnabled returns false). UI Automation providers must reject value-setting requests on disabled elements per the UIA spec. The call never reaches the parse/assign step.","triggerScenarios":"Calling the ValuePattern.SetValue() UIA pattern on a DateTimePicker whose window is disabled (EnableWindow(false), parent dialog showing it disabled, or control disabled during modal operations).","commonSituations":"Automating a dialog while a modal child is open, apps that disable the date control until other fields are valid, test automation racing against UI state changes.","solutions":["Enable the control (EnableWindow(hwnd, TRUE) or app-side change) before invoking SetValue.","Check the element's IsEnabled property via UIA before calling SetValue and skip or wait.","Wait for the control to become enabled (poll IsEnabled or wait for the modal state to end) then retry."],"exampleFix":"// before (test code)\nvaluePattern.SetValue(\"01/02/2024\");\n// after\nif (element.Current.IsEnabled)\n    valuePattern.SetValue(\"01/02/2024\");\nelse\n    throw new SkipException(\"DateTimePicker is disabled\");","handlingStrategy":"validation","validationCode":"if (!element.Current.IsEnabled) throw new InvalidOperationException(\"DateTimePicker is disabled; cannot SetValue.\");","typeGuard":null,"tryCatchPattern":"try { valuePattern.SetValue(text); } catch (ElementNotEnabledException) { /* enable/wait and retry or skip */ }","preventionTips":["Check IsEnabled before every pattern call","Wait for modal dialogs to close before automating","Avoid disabling the picker in app code while automation runs"],"tags":["uiautomation","winforms","disabled-control"],"backgroundTag":"element-not-enabled","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}