{"record":{"id":"00587274249bd0b3","repo":"AvaloniaUI/Avalonia","slug":"the-parameter-value-must-be-greater-than-zero","errorCode":null,"errorMessage":"The parameter value must be greater than zero.","messagePattern":"The parameter value must be greater than zero\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/FormattedText.cs","lineNumber":104,"sourceCode":"                flowDirection,\n                TextAlignment.Left,\n                false,\n                false,\n                runProps,\n                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));","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/FormattedText.cs#L86-L122","documentation":"FormattedText.ValidateFontSize rejects a non-positive emSize because font metrics and layout math divide by em size and produce nonsensical metrics at or below zero. The guard runs in the FormattedText constructor before any layout work.","triggerScenarios":"Constructing FormattedText with FontSize bound from a Slider whose Minimum is not clamped at 0; binding FontSize to a calculated value that can go to 0 or negative on edge cases; passing a default double (0) from an uninitialized field.","commonSituations":"A XAML binding where the user can drag font size to zero; default(double) being passed because a property initializer was skipped; animating FontSize to 0 as a 'fade' trick.","solutions":["Clamp the user-facing font size to a small positive minimum (e.g. 1.0) before constructing FormattedText.","Validate bound input in the view-model setter and reject/coerce values <= 0.","Use double.IsFinite checks upstream to also catch NaN/Infinity.","Set a sensible default emSize (e.g. the system UI font size) so uninitialized fields do not hit the API with 0."],"exampleFix":"// before\nvar ft = new FormattedText(text, fontFamily, requestedSize, ...); // requestedSize may be 0\n\n// after\nvar safeSize = double.IsFinite(requestedSize) && requestedSize > 0 ? requestedSize : 12.0;\nvar ft = new FormattedText(text, fontFamily, safeSize, ...);","handlingStrategy":"validation","validationCode":"static double CoerceFontSize(double v) => double.IsFinite(v) && v > 0 ? v : 12.0;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp bound font sizes to [1.0, MaxFontEmSize].","Set non-zero defaults on font size properties.","Use IsFinite checks upstream to catch NaN/Infinity too."],"tags":["text","formatted-text","font-size","argument-validation","precondition"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}