{"record":{"id":"658bbb32f7cd3b98","repo":"AvaloniaUI/Avalonia","slug":"font-stretch-must-be-1","errorCode":null,"errorMessage":"Font stretch must be > 1.","messagePattern":"Font stretch must be > 1\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/Typeface.cs","lineNumber":33,"sourceCode":"        /// Initializes a new instance of the <see cref=\"Typeface\"/> class.\n        /// </summary>\n        /// <param name=\"fontFamily\">The font family.</param>\n        /// <param name=\"style\">The font style.</param>\n        /// <param name=\"weight\">The font weight.</param>\n        /// <param name=\"stretch\">The font stretch.</param>\n        public Typeface(FontFamily fontFamily,\n            FontStyle style = FontStyle.Normal,\n            FontWeight weight = FontWeight.Normal,\n            FontStretch stretch = FontStretch.Normal)\n        {\n            if (weight <= 0)\n            {\n                throw new ArgumentException(\"Font weight must be > 0.\");\n            }\n            \n            if ((int)stretch < 1)\n            {\n                throw new ArgumentException(\"Font stretch must be > 1.\");\n            }\n\n            FontFamily = fontFamily ?? FontFamily.Default;\n            Style = style;\n            Weight = weight;\n            Stretch = stretch;\n        }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"Typeface\"/> class.\n        /// </summary>\n        /// <param name=\"fontFamilyName\">The name of the font family.</param>\n        /// <param name=\"style\">The font style.</param>\n        /// <param name=\"weight\">The font weight.</param>\n        /// <param name=\"stretch\">The font stretch.</param>\n        public Typeface(string fontFamilyName,\n            FontStyle style = FontStyle.Normal,\n            FontWeight weight = FontWeight.Normal,","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/Typeface.cs#L15-L51","documentation":"Thrown by the Typeface constructor when FontStretch, cast to int, is less than 1. FontStretch values are positive integers (e.g. FontStretch.Normal is 5). A stretch of 0 or negative is invalid because the font selection pipeline cannot match it.","triggerScenarios":"Constructing a Typeface with stretch cast to int < 1, e.g. new Typeface(family, stretch: (FontStretch)0). This happens when an uninitialized or out-of-range stretch value is supplied.","commonSituations":"Casting a numeric config value to FontStretch where it is 0 or negative; default(FontStretch) confusion (the Normal default is 5, not 0); deserialization of a stretch field left unset.","solutions":["Use a valid FontStretch such as FontStretch.Normal (5) or FontStretch.Condensed (3).","Validate: if ((int)stretch < 1) stretch = FontStretch.Normal.","Ensure any deserialized stretch value falls in the valid positive range."],"exampleFix":"// before\nvar typeface = new Typeface(family, stretch: (FontStretch)0); // throws\n\n// after\nvar typeface = new Typeface(family, stretch: FontStretch.Normal);","handlingStrategy":"validation","validationCode":"static Typeface SafeTypefaceStretch(FontFamily f, FontStyle st, FontWeight w, FontStretch sr)\n{\n    if ((int)sr < 1) sr = FontStretch.Normal;\n    return new Typeface(f, st, w, sr);\n}","typeGuard":"static bool IsValidStretch(FontStretch s) => (int)s >= 1;","tryCatchPattern":null,"preventionTips":["Default any unconfigured stretch to FontStretch.Normal (5).","Validate deserialized stretch values fall in the positive range.","Avoid casting non-positive ints to FontStretch."],"tags":["font","typeface","argument-validation","avalonia"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}