{"record":{"id":"21399ca2134e04e7","repo":"dotnet/wpf","slug":"sr-scrollviewer-cannotbenan","errorCode":null,"errorMessage":"SR.ScrollViewer_CannotBeNaN","messagePattern":"SR\\.ScrollViewer_CannotBeNaN","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ScrollContentPresenter.cs","lineNumber":679,"sourceCode":"                return topChild;\n            }\n\n            // Handle Cases: 2 & 3 above\n            else if (fAbove || fBelow || alignBottom)\n            {\n                alignBottom = true;\n                return (bottomChild - (bottomView - topView));\n            }\n\n            // Handle cases: 5 & 6 above.\n            return topView;\n        }\n\n        internal static double ValidateInputOffset(double offset, string parameterName)\n        {\n            if (double.IsNaN(offset))\n            {\n                throw new ArgumentOutOfRangeException(parameterName, SR.Format(SR.ScrollViewer_CannotBeNaN, parameterName));\n            }\n            return Math.Max(0.0, offset);\n        }\n\n        #endregion\n\n        //-------------------------------------------------------------------\n        //\n        //  Private Methods\n        //\n        //-------------------------------------------------------------------\n\n        #region Private Methods\n\n        private ScrollData EnsureScrollData()\n        {\n            if (_scrollData == null) { _scrollData = new ScrollData(); }\n            return _scrollData;","sourceCodeStart":661,"sourceCodeEnd":697,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ScrollContentPresenter.cs#L661-L697","documentation":"ScrollContentPresenter.ValidateInputOffset (invoked from scroll offset property-change callbacks) rejects NaN offsets with ArgumentOutOfRangeException because NaN would corrupt scrolling arithmetic (HorizontalOffset/VerticalOffset). Any non-NaN negative value is silently clamped to 0. The parameter name (offset or viewportWidth/Height context) is included in the message.","triggerScenarios":"Setting ScrollViewer.HorizontalOffset/VerticalOffset, calling ScrollToHorizontalOffset/ScrollToVerticalOffset, or ScrollIntoView with double.NaN; data-binding an offset to a NaN-producing value (e.g. double division 0/0, unset double in code).","commonSituations":"Binding offsets to computed values that yield NaN (divide by zero on doubles), restoring persisted offsets where 'unset' was saved as NaN, custom scrolling logic passing Math-based NaN results.","solutions":["Validate the offset before passing it: replace NaN with 0 or a sensible default (double.IsNaN check).","Fix the computation producing NaN (usually 0/0 or Infinity - Infinity) upstream.","When persisting offsets, serialize 'not set' as 0 or null, never double.NaN.","For bindings, use a value converter that maps NaN to 0, or FallbackValue on the binding."],"exampleFix":"// before\nscrollViewer.ScrollToVerticalOffset(ComputeOffset()); // may be NaN\n// after\ndouble off = ComputeOffset();\nscrollViewer.ScrollToVerticalOffset(double.IsNaN(off) ? 0 : off);","handlingStrategy":"validation","validationCode":"if (double.IsNaN(offset)) offset = 0; // or clamp before passing\noffset = Math.Max(0.0, offset);","typeGuard":"bool IsValidScrollOffset(double v) => !double.IsNaN(v) && !double.IsInfinity(v);","tryCatchPattern":"try { scrollViewer.ScrollToVerticalOffset(offset); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ActualValue is double d && double.IsNaN(d)) { offset = 0; }","preventionTips":["Sanitize any computed offset with double.IsNaN before use","Never persist NaN as a stored offset value","Use binding FallbackValue/converters for offset bindings","Fix divide-by-zero in offset computation upstream"],"tags":["wpf","scrollviewer","nan","argument-out-of-range"],"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"}