{"record":{"id":"53725acd92267b4a","repo":"AvaloniaUI/Avalonia","slug":"parameter-must-be-greater-than-or-equal-to-zero","errorCode":null,"errorMessage":"Parameter must be greater than or equal to zero.","messagePattern":"Parameter must be greater than or equal to zero\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/FormattedText.cs","lineNumber":1061,"sourceCode":"                InvalidateMetrics();\n            }\n            get\n            {\n                return _defaultParaProps.TextAlignment;\n            }\n        }\n\n        /// <summary>\n        /// Gets or sets the height of, or the spacing between, each line where\n        /// zero represents the default line height.\n        /// </summary>\n        public double LineHeight\n        {\n            set\n            {\n                if (value < 0)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(value), \"Parameter must be greater than or equal to zero.\");\n                }\n\n                _defaultParaProps.SetLineHeight(value);\n\n                InvalidateMetrics();\n            }\n            get\n            {\n                return _defaultParaProps.LineHeight;\n            }\n        }\n\n        /// <summary>\n        /// The MaxTextWidth property defines the alignment edges for the FormattedText.\n        /// For example, left aligned text is wrapped such that the leftmost glyph alignment point\n        /// on each line falls exactly on the left edge of the rectangle.\n        /// Note that for many fonts, especially in italic style, some glyph strokes may extend beyond the edges of the alignment rectangle.\n        /// For this reason, it is recommended that clients draw text with at least 1/6 em (i.e of the font size) unused margin space either side.","sourceCodeStart":1043,"sourceCodeEnd":1079,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/FormattedText.cs#L1043-L1079","documentation":"FormattedText.LineHeight setter rejects negative values because a negative line height makes line-breaking math produce overlapping or negative rectangles and breaks cursor/hit-testing. Zero is allowed (meaning the default line height).","triggerScenarios":"Binding LineHeight to a Slider with Minimum < 0; reading LineHeight from a config file where the sign was mis-entered; computing LineHeight as a multiplier that can go negative (e.g. baseHeight * -1).","commonSituations":"User-customizable line spacing UI without a non-negative constraint; defaulting a nullable double to -1 as a sentinel and forgetting to map it to null/0 before setting LineHeight.","solutions":["Clamp the value to [0, +Inf) before setting: value = Math.Max(0, value).","Use 0 to mean 'default' rather than a negative sentinel.","Constrain the input source (slider Minimum=0, numeric input validator).","Add an IValueConverter that coerces negative bound values to 0."],"exampleFix":"// before\nft.LineHeight = requested; // requested may be -1 sentinel\n\n// after\nft.LineHeight = requested < 0 ? 0 : requested;","handlingStrategy":"validation","validationCode":"double lh = double.IsFinite(value) ? Math.Max(0, value) : 0;\nft.LineHeight = lh;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 0 to mean 'default line height' rather than negative sentinels.","Constrain line-spacing inputs to Minimum=0.","Coerce bound values in an IValueConverter."],"tags":["text","formatted-text","layout","line-height","argument-validation"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}