{"record":{"id":"003f6379ba3dcd84","repo":"dotnet/wpf","slug":"sr-propertyvaluecannotbenan-maxtextheight","errorCode":null,"errorMessage":"SR.PropertyValueCannotBeNaN (MaxTextHeight)","messagePattern":"SR\\.PropertyValueCannotBeNaN \\(MaxTextHeight\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs","lineNumber":1302,"sourceCode":"        {\n            return (_maxTextWidths == null) ? null : (double [])_maxTextWidths.Clone();\n        }\n\n        /// <summary>\n        /// Sets the maximum length of a column of text.\n        /// The last line of text displayed is the last whole line that will fit within this limit,\n        /// or the nth line as specified by MaxLineCount, whichever occurs first.\n        /// Use the Trimming property to control how the omission of text is indicated.\n        /// </summary>\n        public double MaxTextHeight\n        {\n            set\n            {\n                if (value <= 0)\n                    throw new ArgumentOutOfRangeException(nameof(value), SR.Format(SR.PropertyMustBeGreaterThanZero, \"MaxTextHeight\"));\n\n                if (double.IsNaN(value))\n                    throw new ArgumentOutOfRangeException(nameof(value), SR.Format(SR.PropertyValueCannotBeNaN, \"MaxTextHeight\"));\n\n                _maxTextHeight = value;\n                InvalidateMetrics();\n            }\n            get\n            {\n                return _maxTextHeight;\n            }\n        }\n\n        /// <summary>\n        /// Defines the maximum number of lines to display.\n        /// The last line of text displayed is the lineCount-1'th line,\n        /// or the last whole line that will fit within the count set by MaxTextHeight,\n        /// whichever occurs first.\n        /// Use the Trimming property to control how the omission of text is indicated\n        /// </summary>\n        public int MaxLineCount","sourceCodeStart":1284,"sourceCodeEnd":1320,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs#L1284-L1320","documentation":"FormattedText.MaxTextHeight setter throws ArgumentOutOfRangeException when the assigned value is double.NaN. After the >0 check, the setter explicitly rejects NaN because an unbounded sentinel in WPF text layout is PositiveInfinity, not NaN.","triggerScenarios":"Assigning double.NaN to FormattedText.MaxTextHeight, typically via a databound/computed value where a division by zero or an unset measurement produced NaN.","commonSituations":"Propagating NaN from layout math (e.g., 0/0 when measuring available space) or from a double property that was never initialized, then handing it to FormattedText for text rendering.","solutions":["Check double.IsNaN(height) before assigning and replace with double.PositiveInfinity if unconstrained height is intended.","Fix the upstream calculation so it yields a finite positive height instead of NaN.","Use double.PositiveInfinity explicitly for 'no height limit' rather than NaN."],"exampleFix":"// before\nformattedText.MaxTextHeight = computedHeight; // may be NaN\n\n// after\nformattedText.MaxTextHeight = double.IsNaN(computedHeight) ? double.PositiveInfinity : computedHeight;","handlingStrategy":"validation","validationCode":"if (double.IsNaN(height)) height = double.PositiveInfinity;\nformattedText.MaxTextHeight = height;","typeGuard":"bool IsFinitePositive(double v) => !double.IsNaN(v) && !double.IsNegativeInfinity(v) && v > 0;","tryCatchPattern":null,"preventionTips":["Use double.PositiveInfinity, never NaN, as the 'unbounded' sentinel for WPF text layout.","Trace NaN sources (0/0 division, uninitialized doubles) in measurement code feeding FormattedText.","Centralize constraint computation in a helper that guarantees finite, positive outputs."],"tags":["wpf","nan","argument-out-of-range"],"backgroundTag":"invalid-argument-value","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"}