{"record":{"id":"e50b281d74b82fce","repo":"dotnet/wpf","slug":"sr-uia-operationcannotbeperformed-scrollviewerautomationpeer","errorCode":null,"errorMessage":"SR.UIA_OperationCannotBePerformed","messagePattern":"SR\\.UIA_OperationCannotBePerformed","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ScrollViewerAutomationPeer.cs","lineNumber":85,"sourceCode":"        /// <summary>\n        /// Request to scroll horizontally and vertically by the specified amount.\n        /// The ability to call this method and simultaneously scroll horizontally\n        /// and vertically provides simple panning support.\n        /// </summary>\n        /// <see cref=\"IScrollProvider.Scroll\"/>\n        void IScrollProvider.Scroll(ScrollAmount horizontalAmount, ScrollAmount verticalAmount)\n        {\n            if(!IsEnabled())\n                throw new ElementNotEnabledException();\n\n            bool scrollHorizontally = (horizontalAmount != ScrollAmount.NoAmount);\n            bool scrollVertically = (verticalAmount != ScrollAmount.NoAmount);\n\n            ScrollViewer owner = (ScrollViewer)Owner;\n\n            if (scrollHorizontally && !HorizontallyScrollable || scrollVertically && !VerticallyScrollable)\n            {\n                throw new InvalidOperationException(SR.UIA_OperationCannotBePerformed);\n            }\n\n            switch (horizontalAmount)\n            {\n                case ScrollAmount.LargeDecrement:\n                    owner.PageLeft();\n                    break;\n                case ScrollAmount.SmallDecrement:\n                    owner.LineLeft();\n                    break;\n                case ScrollAmount.SmallIncrement:\n                    owner.LineRight();\n                    break;\n                case ScrollAmount.LargeIncrement:\n                    owner.PageRight();\n                    break;\n                case ScrollAmount.NoAmount:\n                    break;","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ScrollViewerAutomationPeer.cs#L67-L103","documentation":"ScrollViewerAutomationPeer.Scroll throws InvalidOperationException(SR.UIA_OperationCannotBePerformed) when a scroll amount is requested on an axis that is not scrollable. If horizontal scrolling is requested while HorizontallyScrollable is false, or vertical while VerticallyScrollable is false, the operation cannot be performed.","triggerScenarios":"Calling Scroll with a non-NoAmount horizontal amount when ScrollViewer.HorizontalScrollBarVisibility/extent makes it non-scrollable (ScrollUnit-based HorizontallyScrollable property false), or same for vertical.","commonSituations":"Requesting horizontal scroll on a viewer whose content fits horizontally (scrollbar hidden); scripts assuming both axes are scrollable.","solutions":["Check the Scroll pattern's HorizontallyScrollable/VerticallyScrollable properties before calling Scroll","Pass ScrollAmount.NoAmount for the non-scrollable axis","Ensure content is large enough / ScrollViewer allows scrolling on that axis","Catch InvalidOperationException and treat as no-op"],"exampleFix":"// before\nscrollPattern.Scroll(ScrollAmount.SmallIncrement, ScrollAmount.NoAmount);\n// after\nif (scrollPattern HorizontallyScrollable)\n    scrollPattern.Scroll(ScrollAmount.SmallIncrement, ScrollAmount.NoAmount);","handlingStrategy":"validation","validationCode":"var sp = (IScrollProvider)peer.GetPattern(PatternInterface.Scroll);\nbool ok = (h == ScrollAmount.NoAmount || sp.HorizontallyScrollable)\n       && (v == ScrollAmount.NoAmount || sp.VerticallyScrollable);","typeGuard":"static bool CanScrollAxis(IScrollProvider sp, ScrollAmount h, ScrollAmount v) =>\n    (h == ScrollAmount.NoAmount || sp.HorizontallyScrollable) &&\n    (v == ScrollAmount.NoAmount || sp.VerticallyScrollable);","tryCatchPattern":"try { sp.Scroll(h, v); }\ncatch (InvalidOperationException) { /* axis not scrollable */ }","preventionTips":["Query HorizontallyScrollable/VerticallyScrollable before Scroll","Use NoAmount for non-scrollable axes","Ensure ScrollViewer extent exceeds viewport on the axis you scroll","Account for ScrollViewer scroll bar visibility settings"],"tags":["wpf","ui-automation","invalid-operation","scroll"],"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"}