{"record":{"id":"c739d4aae0d8b470","repo":"dotnet/wpf","slug":"sr-format-sr-scrollviewer-outofrange-horizontalpercent","errorCode":null,"errorMessage":"SR.Format(SR.ScrollViewer_OutOfRange, \"horizontalPercent\", horizontalPercent.ToString(CultureInfo.InvariantCulture), \"0\", \"100\")","messagePattern":"SR\\.Format\\(SR\\.ScrollViewer_OutOfRange, \"horizontalPercent\", horizontalPercent\\.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":153,"sourceCode":"        /// <see cref=\"IScrollProvider.SetScrollPercent\"/>\n        void IScrollProvider.SetScrollPercent(double horizontalPercent, double verticalPercent)\n        {\n            if(!IsEnabled())\n                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","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ScrollViewerAutomationPeer.cs#L135-L171","documentation":"ScrollViewerAutomationPeer.SetScrollPercent throws ArgumentOutOfRangeException with SR.ScrollViewer_OutOfRange when horizontalPercent is outside the valid 0-100 range (and not the NoScroll sentinel -1). Note the condition `scrollHorizontally && (horizontalPercent < 0.0) || (horizontalPercent > 100.0)` means a non-scrollable-axis check also reaches here with out-of-range values.","triggerScenarios":"Calling SetScrollPercent with horizontalPercent < 0 (other than NoScroll -1) or > 100 — e.g. normalized fractions like 0.5 or 1.0 intended as percent.","commonSituations":"Passing normalized scroll ratios (0..1) instead of percentages (0..100); COM clients sending NaN/odd values; NegativeGet off-by-one like 150.","solutions":["Convert ratios to percentages: multiply by 100 before calling","Use ScrollPatternIdentifiers.NoScroll (-1) to skip an axis","Clamp values to the 0-100 range before the call","Catch ArgumentOutOfRangeException and log/normalize the input"],"exampleFix":"// before\nscrollPattern.SetScrollPercent(0.75, ScrollPatternIdentifiers.NoScroll); // ratio!\n// after\nscrollPattern.SetScrollPercent(75.0, ScrollPatternIdentifiers.NoScroll); // percent","handlingStrategy":"validation","validationCode":"if (h != ScrollPatternIdentifiers.NoScroll && (h < 0.0 || h > 100.0))\n    throw new ArgumentException(\"horizontalPercent must be 0-100 or NoScroll\");","typeGuard":"static bool IsValidPercent(double p) =>\n    p == ScrollPatternIdentifiers.NoScroll || (p >= 0.0 && p <= 100.0);","tryCatchPattern":"try { sp.SetScrollPercent(h, v); }\ncatch (ArgumentOutOfRangeException e) { /* clamp/normalize and retry */ }","preventionTips":["Remember SetScrollPercent takes 0-100, not 0-1 ratios","Use NoScroll (-1) to skip an axis, not 0","Clamp inputs to [0,100] before calling","Beware NaN/uninitialized doubles from interop"],"tags":["wpf","ui-automation","argument-out-of-range","scroll"],"backgroundTag":"value-out-of-range","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"}