{"record":{"id":"0b6d0e44dfbe1ee9","repo":"dotnet/wpf","slug":"sr-format-sr-propertymustbegreaterthanzero-maxtextheight","errorCode":null,"errorMessage":"SR.Format(SR.PropertyMustBeGreaterThanZero, \"MaxTextHeight\")","messagePattern":"SR\\.Format\\(SR\\.PropertyMustBeGreaterThanZero, \"MaxTextHeight\"\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs","lineNumber":1299,"sourceCode":"        /// </summary>\n        /// <returns>The copy of max text width array</returns>\n        public double [] GetMaxTextWidths()\n        {\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.","sourceCodeStart":1281,"sourceCodeEnd":1317,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs#L1281-L1317","documentation":"FormattedText.MaxTextHeight setter throws ArgumentOutOfRangeException when the assigned value is <= 0. MaxTextHeight bounds the height of the text layout, so a non-positive value is meaningless and rejected before it invalidates layout metrics.","triggerScenarios":"Assigning MaxTextHeight a value of 0, a negative number, or double.NegativeInfinity on a System.Windows.Media.FormattedText instance.","commonSituations":"Computing the max height from a measurement that returned 0 (e.g., an empty element's ActualHeight, an unmeasured control, or a failed size computation) and passing it straight to MaxTextHeight before rendering text.","solutions":["Ensure the value assigned to MaxTextHeight is strictly greater than 0 before setting it.","Clamp or substitute a sensible default (e.g., double.PositiveInfinity for unconstrained height) when the computed height is 0 or negative.","Guard against NaN separately — NaN fails the later NaN check, but negative infinity fails this one first."],"exampleFix":"// before\nformattedText.MaxTextHeight = availableHeight; // availableHeight may be 0\n\n// after\nformattedText.MaxTextHeight = Math.Max(availableHeight, 1.0);","handlingStrategy":"validation","validationCode":"if (double.IsNaN(height) || height <= 0)\n    height = height == 0 || double.IsNaN(height) ? double.PositiveInfinity : 1.0;\nformattedText.MaxTextHeight = height;","typeGuard":"bool IsValidMaxTextHeight(double v) => !double.IsNaN(v) && v > 0;","tryCatchPattern":null,"preventionTips":["Never assign measured sizes of 0 straight into MaxTextHeight; clamp to a minimum of 1 or PositiveInfinity.","Check IsLoaded/measured state before using ActualHeight as a layout constraint.","Validate NaN and non-positive values in one shared helper before constructing FormattedText."],"tags":["wpf","argument-out-of-range","text-layout"],"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"}