{"record":{"id":"999f7ca24064a897","repo":"AvaloniaUI/Avalonia","slug":"invalid-nameof-textrunproperties-fontrenderingems","errorCode":null,"errorMessage":"Invalid {nameof(TextRunProperties.FontRenderingEmSize)}","messagePattern":"Invalid (.+?)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/TextFormatting/TextCharacters.cs","lineNumber":35,"sourceCode":"        private const char WordJoiner = '\\u2060';\n        private static readonly string s_wordJoinerRun = new string(WordJoiner, 8);\n\n        /// <summary>\n        /// Constructs a run for text content from a string.\n        /// </summary>\n        public TextCharacters(string text, TextRunProperties textRunProperties)\n            : this(text.AsMemory(), textRunProperties)\n        {\n        }\n\n        /// <summary>\n        /// Constructs a run for text content from a memory region.\n        /// </summary>\n        public TextCharacters(ReadOnlyMemory<char> text, TextRunProperties textRunProperties)\n        {\n            if (textRunProperties.FontRenderingEmSize <= 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(textRunProperties), textRunProperties.FontRenderingEmSize,\n                    $\"Invalid {nameof(TextRunProperties.FontRenderingEmSize)}\");\n            }\n\n            Text = text;\n            Properties = textRunProperties;\n        }\n\n        /// <inheritdoc />\n        public override int Length\n            => Text.Length;\n\n        /// <inheritdoc />\n        public override ReadOnlyMemory<char> Text { get; }\n\n        /// <inheritdoc />\n        public override TextRunProperties Properties { get; }\n\n        /// <summary>","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/TextFormatting/TextCharacters.cs#L17-L53","documentation":"Thrown by the TextCharacters constructor when the supplied TextRunProperties has a FontRenderingEmSize that is zero or negative. FontRenderingEmSize represents the font size in EM units used to render the text run; it must be a strictly positive number. Avalonia rejects non-positive sizes early because the text layout engine cannot shape or measure glyphs without a valid em size.","triggerScenarios":"Constructing a new TextCharacters(string, TextRunProperties) or TextCharacters(ReadOnlyMemory<char>, TextRunProperties) where the GenericTextRunProperties.FontRenderingEmSize (or any TextRunProperties implementation) is set to 0, a negative value, or left at a default of 0 on a custom properties object.","commonSituations":"Creating a custom TextRunProperties implementation whose FontRenderingEmSize defaults to 0; passing a properties object that was only partially initialized; copying properties from a style or template that did not set a font size; unit confusion where a size in points or pixels was never assigned.","solutions":["Ensure the TextRunProperties.FontRenderingEmSize is set to a positive value (e.g. 12) before constructing TextCharacters.","If building GenericTextRunProperties programmatically, pass a valid typeface with the desired font size in the constructor or set the property explicitly.","Validate the font size at the call site with a guard: if (props.FontRenderingEmSize <= 0) throw or assign a sane default.","Check upstream style/template binding to confirm a font size is actually resolved at runtime."],"exampleFix":"// before\nvar props = new GenericTextRunProperties(typeface, 0); // FontRenderingEmSize = 0\nvar run = new TextCharacters(\"hello\", props); // throws\n\n// after\nvar props = new GenericTextRunProperties(typeface, 14);\nvar run = new TextCharacters(\"hello\", props);","handlingStrategy":"validation","validationCode":"static TextCharacters SafeCreate(string text, TextRunProperties props)\n{\n    if (props.FontRenderingEmSize <= 0)\n        throw new ArgumentException(\"FontRenderingEmSize must be > 0.\", nameof(props));\n    return new TextCharacters(text, props);\n}","typeGuard":"static bool IsValidTextRunProperties(TextRunProperties p)\n    => p != null && p.FontRenderingEmSize > 0;","tryCatchPattern":null,"preventionTips":["Always set FontRenderingEmSize explicitly when constructing TextRunProperties.","Add an assertion or guard at the boundary where properties are built.","Avoid custom TextRunProperties subclasses that default FontRenderingEmSize to 0."],"tags":["text-formatting","font-size","argument-validation","avalonia"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}