{"record":{"id":"6bcb7ec8d67dc5c2","repo":"dotnet/wpf","slug":"argumentnullexception-textrunproperties-typeface","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/TextCharacters.cs","lineNumber":114,"sourceCode":"                )\n        {}\n\n\n        /// <summary>\n        /// Internal constructor of TextContent\n        /// </summary>\n        private TextCharacters(\n            CharacterBufferReference    characterBufferReference,\n            int                         length,\n            TextRunProperties           textRunProperties\n            )\n        {\n            ArgumentOutOfRangeException.ThrowIfNegativeOrZero(length);\n            ArgumentNullException.ThrowIfNull(textRunProperties);\n\n            if (textRunProperties.Typeface == null)\n            {\n                throw new ArgumentNullException(\"textRunProperties.Typeface\");\n            }\n\n            if (textRunProperties.CultureInfo == null)\n            {\n                throw new ArgumentNullException(\"textRunProperties.CultureInfo\");\n            }\n\n            ArgumentOutOfRangeException.ThrowIfNegativeOrZero(textRunProperties.FontRenderingEmSize, \"textRunProperties.FontRenderingEmSize\");\n\n            _characterBufferReference = characterBufferReference;\n            _length = length;\n            _textRunProperties = textRunProperties;\n        }\n\n        #endregion\n\n\n        #region TextRun implementation","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextCharacters.cs#L96-L132","documentation":"The TextCharacters constructor requires textRunProperties and specifically its Typeface to be non-null; if textRunProperties.Typeface is null it throws ArgumentNullException(\"textRunProperties.Typeface\"). The typeface is essential to shape and render the character run.","triggerScenarios":"Constructing TextCharacters with a TextRunProperties whose Typeface property is null — e.g. a custom TextRunProperties subclass that never sets Typeface, or a default-constructed instance.","commonSituations":"Custom text source (TextSource.GetTextRun) returning TextCharacters with hand-rolled run properties; forgetting to set Typeface when building runs programmatically; a font lookup returning null and being stored into Typeface.","solutions":["Set TextRunProperties.Typeface to a valid Typeface before creating TextCharacters (e.g. new Typeface(\"Segoe UI\"))","Fix a custom TextRunProperties subclass so Typeface is assigned in its constructor","If a font family failed to resolve, fall back to a default: props.Typeface = new Typeface(\"Arial\")","Null-check the typeface in the TextSource before constructing the run"],"exampleFix":"// before\nvar props = new CustomTextRunProperties(); // Typeface never set\nreturn new TextCharacters(text, 0, text.Length, props);\n// after\nvar props = new CustomTextRunProperties\n{\n    Typeface = new Typeface(\"Segoe UI\"),\n    FontRenderingEmSize = 12\n};\nreturn new TextCharacters(text, 0, text.Length, props);","handlingStrategy":"type-guard","validationCode":"if (props?.Typeface == null) props.Typeface = new Typeface(\"Segoe UI\");","typeGuard":"bool HasValidTypeface(TextRunProperties p) => p?.Typeface != null;","tryCatchPattern":"try { return new TextCharacters(text, 0, text.Length, props); }\ncatch (ArgumentNullException ex) { log.Error(\"Run properties missing Typeface\", ex); throw; }","preventionTips":["Initialize Typeface in custom TextRunProperties constructors","Fall back to a default Typeface when font resolution fails","Null-check run properties in TextSource.GetTextRun before building runs"],"tags":["wpf","textformatting","null-argument","typeface"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}