{"record":{"id":"d72c2cd48a031f1e","repo":"AvaloniaUI/Avalonia","slug":"the-parameter-value-cannot-be-greater-than-maxfo","errorCode":null,"errorMessage":"The parameter value cannot be greater than '{MaxFontEmSize}'","messagePattern":"The parameter value cannot be greater than '(.+?)'","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/FormattedText.cs","lineNumber":109,"sourceCode":"                TextWrapping.WrapWithOverflow,\n                0, // line height not specified\n                0, // indentation not specified\n                0\n            );\n\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        {","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/FormattedText.cs#L91-L127","documentation":"ValidateFontSize enforces an upper bound MaxFontEmSize to prevent overflow in the layout pipeline (metrics scale with em size, and an enormous value produces out-of-range pixel rectangles or allocation failures). This guard is the second of three in the validator.","triggerScenarios":"Binding FontSize to a high-value slider without an upper clamp; passing a value computed by a misconfigured zoom factor (e.g. *1000); unit confusion where points/pixels/ems are mixed; an animation overshooting past MaxFontEmSize.","commonSituations":"A 'zoom' feature multiplying the base font size by an unbounded scale; XAML where FontSize is set in code-behind from a config value with no ceiling; binding to a TextBox input parsed as double without clamping.","solutions":["Clamp emSize to a sane maximum (e.g. Math.Min(emSize, FormattedText.MaxFontEmSize)) before construction.","Constrain the input source (slider Maximum, config schema range, numeric up-down upper bound).","Verify the unit; if you meant points, ensure the conversion is correct and not amplified twice.","Unit-test the binding with extreme values (0, negative, MaxValue, NaN, Infinity)."],"exampleFix":"// before\nvar size = baseSize * zoomFactor; // zoomFactor unbounded\nvar ft = new FormattedText(text, font, size, ...);\n\n// after\nconst double maxSize = 35791; // FormattedText.MaxFontEmSize reference\nvar size = Math.Clamp(baseSize * zoomFactor, 1.0, maxSize);\nvar ft = new FormattedText(text, font, size, ...);","handlingStrategy":"validation","validationCode":"static double ClampEmSize(double v)\n{\n    const double MaxEm = 35791;\n    if (!double.IsFinite(v)) return 12.0;\n    return Math.Clamp(v, 1.0, MaxEm);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Constrain zoom factors and font-size sliders with an upper bound.","Verify the unit (points vs ems) before multiplying.","Test bindings with extreme inputs."],"tags":["text","formatted-text","font-size","bounds","overflow","argument-validation"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}