{"record":{"id":"439c3223bd99c5e4","repo":"dotnet/wpf","slug":"argumentnullexception-textrunproperties-typeface-439c32","errorCode":null,"errorMessage":"ArgumentNullException(\"textRunProperties.Typeface\")","messagePattern":"ArgumentNullException\\(\"textRunProperties\\.Typeface\"\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextEndOfLine.cs","lineNumber":46,"sourceCode":"        /// <param name=\"length\">number of characters</param>\n        public TextEndOfLine(int length) : this(length, null)\n        {}\n\n\n        /// <summary>\n        /// Construct a linebreak run\n        /// </summary>\n        /// <param name=\"length\">number of characters</param>\n        /// <param name=\"textRunProperties\">linebreak text run properties</param>\n        public TextEndOfLine(\n            int                 length, \n            TextRunProperties   textRunProperties\n            )\n        {\n            ArgumentOutOfRangeException.ThrowIfNegativeOrZero(length);\n\n            if (textRunProperties != null && textRunProperties.Typeface == null)\n                throw new ArgumentNullException(\"textRunProperties.Typeface\");\n\n            _length = length;\n            _textRunProperties = textRunProperties;\n        }\n\n        #endregion\n\n\n        /// <summary>\n        /// Reference to character buffer\n        /// </summary>\n        public sealed override CharacterBufferReference CharacterBufferReference\n        {\n            get { return new CharacterBufferReference(); }\n        }\n\n        \n        /// <summary>","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextEndOfLine.cs#L28-L64","documentation":"The TextEndOfLine constructor accepts null textRunProperties, but if provided, its Typeface must not be null — otherwise ArgumentNullException(\"textRunProperties.Typeface\") is thrown. TextEndOfLine represents line-break runs, and a non-null properties object must carry a usable typeface.","triggerScenarios":"Constructing TextEndOfLine (or subclass TextEndOfParagraph) with a TextRunProperties instance whose Typeface is null — e.g. a partially initialized custom TextRunProperties.","commonSituations":"Custom TextSource returning TextEndOfLine with freshly created run properties where Typeface was left unset; copying properties from a run whose typeface failed to resolve to null.","solutions":["Either pass a fully initialized TextRunProperties (Typeface set) or pass null instead of an empty properties object","Set props.Typeface = new Typeface(\"Segoe UI\") (or the paragraph's typeface) before constructing TextEndOfLine","Fix custom TextRunProperties to always initialize Typeface in the constructor","Guard in the TextSource: only construct TextEndOfLine when props?.Typeface != null, else pass null"],"exampleFix":"// before\nvar props = new CustomTextRunProperties(); // Typeface null\nreturn new TextEndOfLine(1, props);\n// after\nreturn new TextEndOfLine(1, null); // or set props.Typeface = new Typeface(\"Segoe UI\");","handlingStrategy":"type-guard","validationCode":"if (props != null && props.Typeface == null) props = null; // or set a default typeface","typeGuard":"bool IsUsableProps(TextRunProperties p) => p == null || p.Typeface != null;","tryCatchPattern":"try { return new TextEndOfLine(1, props); }\ncatch (ArgumentNullException ex) { log.Warn(\"EndOfLine props had null Typeface; retrying with null\", ex); return new TextEndOfLine(1, null); }","preventionTips":["Pass null instead of an uninitialized TextRunProperties to TextEndOfLine","Always set Typeface when creating run properties","Share a fully initialized paragraph properties object for line-break runs"],"tags":["wpf","textformatting","null-argument","textrun"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}