{"record":{"id":"88bc8a3d872f5b2d","repo":"AvaloniaUI/Avalonia","slug":"maxtextheight-property-value-cannot-be-nan","errorCode":null,"errorMessage":"'MaxTextHeight' property value cannot be NaN.","messagePattern":"'MaxTextHeight' property value cannot be NaN\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/FormattedText.cs","lineNumber":1151,"sourceCode":"\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                {\n                    throw new ArgumentOutOfRangeException(nameof(value), $\"'{nameof(MaxTextHeight)}' property value must be greater than zero.\");\n                }\n\n                if (double.IsNaN(value))\n                {\n                    throw new ArgumentOutOfRangeException(nameof(value), $\"'{nameof(MaxTextHeight)}' property value cannot be NaN.\");\n                }\n\n                _maxTextHeight = value;\n\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","sourceCodeStart":1133,"sourceCodeEnd":1169,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/FormattedText.cs#L1133-L1169","documentation":"MaxTextHeight additionally rejects NaN. Because NaN contaminates any comparison (NaN > 0 is false, NaN <= 0 is false), the prior guard would not catch it; this explicit check ensures the field never stores a non-numeric value.","triggerScenarios":"Binding MaxTextHeight to a computation that yields 0/0; deserialization producing NaN from a missing field; a zoom factor of Infinity multiplied by 0.","commonSituations":"View-model division by zero feeding MaxTextHeight; XAML converter returning NaN for an unset value; animation interpolation crossing a NaN.","solutions":["Filter with double.IsFinite(value) before assigning; substitute a positive default for non-finite values.","Fix the upstream computation producing NaN.","Use a nullable double in the model so 'unset' is distinct from 'set to NaN'.","Add unit tests covering NaN/Infinity edge cases."],"exampleFix":"// before\nft.MaxTextHeight = computed; // computed may be NaN\n\n// after\nft.MaxTextHeight = double.IsFinite(computed) && computed > 0\n    ? computed\n    : double.PositiveInfinity;","handlingStrategy":"validation","validationCode":"if (double.IsFinite(value) && value > 0) ft.MaxTextHeight = value;\nelse /* leave unset / use no limit */ ;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Filter with double.IsFinite before assignment.","Fix upstream NaN computations.","Prefer nullable double in the model to distinguish 'unset' from 'NaN'."],"tags":["text","formatted-text","layout","height","nan","numeric-safety"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}