{"record":{"id":"058bdcdaa863c7a3","repo":"AvaloniaUI/Avalonia","slug":"the-parameter-value-must-be-a-number","errorCode":null,"errorMessage":"The parameter value must be a number.","messagePattern":"The parameter value must be a number\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/FormattedText.cs","lineNumber":114,"sourceCode":"\n            InvalidateMetrics();\n        }\n\n        private static void ValidateFontSize(double emSize)\n        {\n            if (emSize <= 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(emSize), \"The parameter value must be greater than zero.\");\n            }\n\n            if (emSize > MaxFontEmSize)\n            {\n                throw new ArgumentOutOfRangeException(nameof(emSize), $\"The parameter value cannot be greater than '{MaxFontEmSize}'\");\n            }\n\n            if (double.IsNaN(emSize))\n            {\n                throw new ArgumentOutOfRangeException(nameof(emSize), \"The parameter value must be a number.\");\n            }\n        }\n\n        private static void ValidateFlowDirection(FlowDirection flowDirection, string parameterName)\n        {\n            if ((int)flowDirection < 0 || (int)flowDirection > (int)FlowDirection.RightToLeft)\n            {\n                throw new InvalidEnumArgumentException(parameterName, (int)flowDirection, typeof(FlowDirection));\n            }\n        }\n\n        private int ValidateRange(int startIndex, int count)\n        {\n            if (startIndex < 0 || startIndex > _text.Length)\n            {\n                throw new ArgumentOutOfRangeException(nameof(startIndex));\n            }\n","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/FormattedText.cs#L96-L132","documentation":"ValidateFontSize rejects NaN because NaN propagates through every arithmetic operation and silently corrupts all subsequent layout metrics (line heights, advance widths, hit-testing rectangles). NaN cannot produce a valid glyph layout.","triggerScenarios":"Binding FontSize to 0.0/0.0 or any computation that yields NaN; reading FontSize from a deserialized source where the value was missing and defaulted to NaN; a multiplication of Infinity * 0 in a zoom calculation.","commonSituations":"A division by zero in a view-model that feeds FontSize; JSON deserialization of a missing numeric field returning NaN on some serializers; XAML binding to a non-numeric source converted by a faulty IValueConverter.","solutions":["Filter with double.IsFinite(emSize) before passing to FormattedText; substitute a sensible default for non-finite values.","Fix the upstream computation producing NaN (guard divisors, check for 0/0).","Add a numeric IValueConverter that maps NaN/Infinity to a fallback font size.","Validate deserialized font sizes against a schema/range and reject missing fields."],"exampleFix":"// before\nvar emSize = (a / b) * scale; // b may be 0 -> NaN propagates\nvar ft = new FormattedText(text, font, emSize, ...);\n\n// after\nvar raw = (a / Math.Max(b, 1)) * scale;\nvar emSize = double.IsFinite(raw) ? raw : 12.0;\nvar ft = new FormattedText(text, font, emSize, ...);","handlingStrategy":"validation","validationCode":"double em = double.IsFinite(requested) ? requested : 12.0;\nem = em > 0 ? em : 12.0;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Filter all numeric inputs with double.IsFinite.","Guard divisors that feed font-size calculations.","Map missing deserialized numerics to a default, not NaN."],"tags":["text","formatted-text","font-size","nan","numeric-safety","argument-validation"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}