{"record":{"id":"dde2cb2b24970b9e","repo":"dotnet/wpf","slug":"elementnotenabledexception-rangebaseautomationpeer","errorCode":null,"errorMessage":"ElementNotEnabledException","messagePattern":"ElementNotEnabledException","errorType":"exception","errorClass":"ElementNotEnabledException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/RangeBaseAutomationPeer.cs","lineNumber":70,"sourceCode":"        internal virtual void SetValueCore(double val)\n        {\n            RangeBase owner = (RangeBase)Owner;\n            ArgumentOutOfRangeException.ThrowIfLessThan(val, owner.Minimum);\n            ArgumentOutOfRangeException.ThrowIfGreaterThan(val, owner.Maximum);\n\n            owner.Value = (double)val;\n        }\n\n        /// <summary>\n        /// Request to set the value that this UI element is representing\n        /// </summary>\n        /// <param name=\"val\">Value to set the UI to, as an object</param>\n        /// <returns>true if the UI element was successfully set to the specified value</returns>\n        //[CodeAnalysis(\"AptcaMethodsShouldOnlyCallAptcaMethods\")] //Tracking Bug: 29647\n        void IRangeValueProvider.SetValue(double val)\n        {\n            if (!IsEnabled())\n                throw new ElementNotEnabledException();\n\n            SetValueCore(val);\n        }\n\n\n        /// <summary>Value of a value control, as an object</summary>\n        double IRangeValueProvider.Value\n        {\n            get\n            {\n                return ((RangeBase)Owner).Value;\n            }\n        }\n\n        ///<summary>Indicates that the value can only be read, not modified.\n        ///returns True if the control is read-only</summary>\n        bool IRangeValueProvider.IsReadOnly\n        {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/RangeBaseAutomationPeer.cs#L52-L88","documentation":"RangeBaseAutomationPeer's IRangeValueProvider.SetValue throws ElementNotEnabledException when the owning control (e.g. Slider, ProgressBar, ScrollBar) is disabled. UIA SetValue requests must not succeed on disabled elements, so the peer explicitly raises this COM-visible UIA exception.","triggerScenarios":"Calling SetValue(double) on the RangeValue pattern when RangeBaseAutomationPeer.IsEnabled() returns false (owner control IsEnabled=false).","commonSituations":"Test scripts setting a Slider value while the control is disabled; UIA clients driving forms where a field is disabled until validation passes.","solutions":["Enable the owner control before setting the value (owner.IsEnabled = true)","Check owner.IsEnabled before issuing the UIA SetValue call","Catch ElementNotEnabledException and surface a 'control disabled' message to the user/test"],"exampleFix":"// before\n((IValueProvider)peer.GetPattern(PatternInterface.RangeValue)).SetValue(50);\n// after\nif (slider.IsEnabled)\n    ((IRangeValueProvider)peer).SetValue(50);\nelse\n    slider.IsEnabled = true; // then set","handlingStrategy":"validation","validationCode":"if (!rangeBase.IsEnabled) throw/return /* handle disabled */;","typeGuard":"static bool CanSetValue(RangeBase c) => c?.IsEnabled == true;","tryCatchPattern":"try { rangeValueProvider.SetValue(val); }\ncatch (ElementNotEnabledException) { /* owner disabled; enable or report */ }","preventionTips":["Check IsEnabled before any UIA pattern call","Keep track of why controls are disabled in your app state","Wait-for-enabled in test automation before interacting","Catch UIA COM exceptions (UIA_E_ELEMENTNOTENABLED) on the client side"],"tags":["wpf","ui-automation","disabled-element"],"backgroundTag":"authentication-required","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}