{"record":{"id":"62c851c40f41ce97","repo":"dotnet/wpf","slug":"sr-operationcannotbeperformed-windowsscrollbar","errorCode":null,"errorMessage":"SR.OperationCannotBePerformed","messagePattern":"SR\\.OperationCannotBePerformed","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsScrollBar.cs","lineNumber":629,"sourceCode":"        }\n\n        private void SetScrollValue (int val)\n        {\n            // Check if the window is disabled\n            if (!SafeNativeMethods.IsWindowEnabled (_hwnd))\n            {\n                throw new ElementNotEnabledException();\n            }\n\n            NativeMethods.ScrollInfo si = new NativeMethods.ScrollInfo\n            {\n                fMask = NativeMethods.SIF_ALL\n            };\n            si.cbSize = Marshal.SizeOf (si.GetType ());\n\n            if (!Misc.GetScrollInfo(_hwnd, _sbFlag, ref si))\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);\n            }\n\n            // No move, exit\n            if (val == si.nPos)\n            {\n                return;\n            }\n\n            // NOTE:\n            // Proportional scrollbars have a few key values: min, max, page, and current.\n            // \n            // Min and max represent the endpoints of the scrollbar; page is the side of the thumb,\n            // and current is the position of the leading edge of the thumb (top for a vert scrollbar).\n            // \n            // Because of this arrangment, current can't be any value between min and max, it's actually\n            // confied to min...(max-page)+1. That +1 is a quirk of the scrollbar's internal logic.\n            // \n            // For example, in an edit in notepad, these might be:","sourceCodeStart":611,"sourceCodeEnd":647,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsScrollBar.cs#L611-L647","documentation":"WindowsScrollBar.SetScrollValue calls Misc.GetScrollInfo to read the current SCROLLINFO of the target bar; if the Win32 GetScrollInfo call fails it throws InvalidOperationException(SR.OperationCannotBePerformed). The RangeValue.SetValue operation cannot proceed because the scrollbar's state is unreadable.","triggerScenarios":"RangeValuePattern.SetValue on a scrollbar/trackbar-backed element where GetScrollInfo(_hwnd, _sbFlag, ref si) returns false, at WindowsScrollBar.cs:629.","commonSituations":"Targeting a scrollbar handle that has been destroyed or recreated between finding the element and setting the value; targeting a control that only pretends to expose the RangeValue pattern; handle invalidation after window layout changes.","solutions":["Re-find the AutomationElement (fresh handle) and retry SetValue; cached/stale hwnd is the usual cause.","Verify the element truly supports RangeValuePattern before calling SetValue.","Catch InvalidOperationException and treat as a transient automation failure with retry."],"exampleFix":"// before\nscrollBarElement.GetCurrentPattern(RangeValuePattern.Pattern).SetValue(50);\n// after\nvar el = treeElement.FindFirst(TreeScope.Children, cond); // re-find fresh element\n((RangeValuePattern)el.GetCurrentPattern(RangeValuePattern.Pattern)).SetValue(50);","handlingStrategy":"retry","validationCode":"if (element.Current.IsOffscreen || !element.Current.IsEnabled) reFind();\n// ensure RangeValue support\nbool supported = element.TryGetCurrentPattern(RangeValuePattern.Pattern, out var p);","typeGuard":null,"tryCatchPattern":"try { rv.SetValue(val); }\ncatch (InvalidOperationException) { element = ReFindElement(); ((RangeValuePattern)element.GetCurrentPattern(RangeValuePattern.Pattern)).SetValue(val); }","preventionTips":["Re-find elements instead of caching them across UI changes","Use TryGetCurrentPattern to confirm RangeValue support","Retry transient Win32 failures with a short delay"],"tags":["uiautomation","invalid-operation","range-value-pattern","wpf"],"backgroundTag":"unsupported-operation","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"}