{"record":{"id":"40a78518c87e6f21","repo":"dotnet/wpf","slug":"sr-format-sr-scrollviewer-outofrange-verticalpercent","errorCode":null,"errorMessage":"SR.Format(SR.ScrollViewer_OutOfRange, \"verticalPercent\", verticalPercent.ToString(CultureInfo.InvariantCulture), \"0\", \"100\")","messagePattern":"SR\\.Format\\(SR\\.ScrollViewer_OutOfRange, \"verticalPercent\", verticalPercent\\.ToString\\(CultureInfo\\.InvariantCulture\\), \"0\", \"100\"\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ScrollViewerAutomationPeer.cs","lineNumber":157,"sourceCode":"                throw new ElementNotEnabledException();\n\n            bool scrollHorizontally = (horizontalPercent != (double)ScrollPatternIdentifiers.NoScroll);\n            bool scrollVertically = (verticalPercent != (double)ScrollPatternIdentifiers.NoScroll);\n\n            ScrollViewer owner = (ScrollViewer)Owner;\n\n            if (scrollHorizontally && !HorizontallyScrollable || scrollVertically && !VerticallyScrollable)\n            {\n                throw new InvalidOperationException(SR.UIA_OperationCannotBePerformed);\n            }\n\n            if (scrollHorizontally && (horizontalPercent < 0.0) || (horizontalPercent > 100.0))\n            {\n                throw new ArgumentOutOfRangeException(nameof(horizontalPercent), SR.Format(SR.ScrollViewer_OutOfRange, \"horizontalPercent\", horizontalPercent.ToString(CultureInfo.InvariantCulture), \"0\", \"100\"));\n            }\n            if (scrollVertically && (verticalPercent < 0.0) || (verticalPercent > 100.0))\n            {\n                throw new ArgumentOutOfRangeException(nameof(verticalPercent), SR.Format(SR.ScrollViewer_OutOfRange, \"verticalPercent\", verticalPercent.ToString(CultureInfo.InvariantCulture), \"0\", \"100\"));\n            }\n\n            if (scrollHorizontally)\n            {\n                owner.ScrollToHorizontalOffset((owner.ExtentWidth - owner.ViewportWidth) * (double)horizontalPercent * 0.01);\n            }\n            if (scrollVertically)\n            {\n                owner.ScrollToVerticalOffset((owner.ExtentHeight - owner.ViewportHeight) * (double)verticalPercent * 0.01);\n            }\n        }\n\n        /// <summary>\n        /// Get the current horizontal scroll position\n        /// </summary>\n        /// <see cref=\"IScrollProvider.HorizontalScrollPercent\"/>\n        double IScrollProvider.HorizontalScrollPercent\n        {","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ScrollViewerAutomationPeer.cs#L139-L175","documentation":"SetScrollPercent validates its scroll percent argument and throws ArgumentOutOfRangeException when the value falls outside the accepted 0-100 range (SR.ScrollViewer_OutOfRange). The WPF automation layer requires percents expressed as a fraction of the total scrollable range, so any value below 0.0 or above 100.0 is rejected before the peer scrolls the owner ScrollViewer. This is a caller-input contract violation, not an internal failure.","triggerScenarios":"Calling ScrollViewerAutomationPeer's IScrollProvider.SetScrollPercent (via UIA clients or directly) with verticalPercent or horizontalPercent < 0.0 or > 100.0 when the content scrolls in that axis; e.g. SetScrollPercent(150.0) or SetScrollPercent(-5). Note the source's && || precedence means the range check only runs when the axis actually scrolls.","commonSituations":"UIA test clients computing percent from pixel offsets and mis-scaling (forgetting the 0.01 factor or using viewport instead of extent); passing special UIA values like -1 (NoScroll) which this implementation does not special-case; scripts written for other frameworks that accept 0-1 fractions instead of 0-100 percents.","solutions":["Clamp or validate the percent to the 0-100 range before calling SetScrollPercent","Compute the percent as offset/(extent-viewport)*100 rather than passing raw pixels","If you intend 'no scrolling', pass null per the UIA contract instead of -1 where supported, or skip the call when the axis cannot scroll"],"exampleFix":"// before\npeer.SetScrollPercent(150.0); // throws ArgumentOutOfRangeException\n// after\ndouble pct = Math.Clamp(150.0, 0.0, 100.0);\npeer.SetScrollPercent(pct);","handlingStrategy":"validation","validationCode":"if (percent < 0.0 || percent > 100.0)\n    throw new ArgumentOutOfRangeException(nameof(percent), \"Scroll percent must be 0-100\");\npeer.SetScrollPercent(percent);","typeGuard":"static bool IsValidScrollPercent(double v) => v >= 0.0 && v <= 100.0;","tryCatchPattern":"try { peer.SetScrollPercent(p); }\ncatch (ArgumentOutOfRangeException ex) { /* clamp or log: ex.ParamName, ex.ActualValue */ }","preventionTips":["Always compute percent as offset/(extent-viewport)*100 and clamp to [0,100]","Never pass raw pixel offsets or UIA sentinel values like -1 to SetScrollPercent","Check the axis actually scrolls; the range check is skipped for non-scrolling axes"],"tags":["wpf","ui-automation","argument-out-of-range","scrollviewer"],"backgroundTag":"argument-out-of-range","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"}