{"record":{"id":"1c0d6348c88558b3","repo":"dotnet/wpf","slug":"sr-argumentoutofrange-generic-mustbefinite","errorCode":null,"errorMessage":"SR.ArgumentOutOfRange_Generic_MustBeFinite","messagePattern":"SR\\.ArgumentOutOfRange_Generic_MustBeFinite","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TextBoxBase.cs","lineNumber":279,"sourceCode":"        /// Vertically scroll to the end of the content.\n        /// </summary>\n        public void ScrollToEnd()\n        {\n            if (this.ScrollViewer != null)\n            {\n                UpdateLayout();\n                this.ScrollViewer.ScrollToEnd();\n            }\n        }\n\n        /// <summary>\n        /// Scroll horizontally to the specified offset.\n        /// </summary>\n        public void ScrollToHorizontalOffset(double offset)\n        {\n            if (Double.IsNaN(offset))\n            {\n                throw new ArgumentOutOfRangeException(nameof(offset));\n            }\n\n            if (this.ScrollViewer != null)\n            {\n                UpdateLayout();\n                this.ScrollViewer.ScrollToHorizontalOffset(offset);\n            }\n        }\n\n        /// <summary>\n        /// Scroll vertically to the specified offset.\n        /// </summary>\n        public void ScrollToVerticalOffset(double offset)\n        {\n            if (Double.IsNaN(offset))\n            {\n                throw new ArgumentOutOfRangeException(nameof(offset));\n            }","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TextBoxBase.cs#L261-L297","documentation":"TextBoxBase.ScrollToHorizontalOffset validates that the offset is a finite number; a NaN offset triggers ArgumentOutOfRangeException (the SR string for 'must be a finite number'). NaN would propagate into ScrollViewer layout math and corrupt scrolling state, so the API rejects it up front.","triggerScenarios":"Calling ScrollToHorizontalOffset(double.NaN), typically from a data binding or computed value that produced NaN (e.g. 0/0 from width calculations, unset double in XAML evaluating to NaN).","commonSituations":"Binding the offset to a property whose getter computes NaN during layout passes; passing Double.NaN as a 'no value' sentinel; math on ActualWidth before layout completes.","solutions":["Check Double.IsNaN(offset) before calling and skip or clamp the call","Pass 0 or a computed finite offset instead of NaN","Ensure bound values are computed after layout (e.g. in Loaded or via Dispatcher.BeginInvoke) so ActualWidth-based math is finite"],"exampleFix":"// before\ntextBox.ScrollToHorizontalOffset(computedOffset); // may be NaN\n// after\nif (!double.IsNaN(computedOffset))\n    textBox.ScrollToHorizontalOffset(computedOffset);","handlingStrategy":"validation","validationCode":"if (double.IsNaN(offset) || double.IsInfinity(offset))\n    return;","typeGuard":"static bool IsFinite(double d) => !double.IsNaN(d) && !double.IsInfinity(d);","tryCatchPattern":"try\n{\n    textBox.ScrollToHorizontalOffset(offset);\n}\ncatch (ArgumentOutOfRangeException)\n{\n    textBox.ScrollToHorizontalOffset(0);\n}","preventionTips":["Check Double.IsNaN before any ScrollTo* call","Avoid passing NaN as a sentinel","Compute offsets after layout completes"],"tags":["wpf","textboxbase","scroll","argumentoutofrange","nan"],"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-21T21:30:21.729Z"}