{"record":{"id":"5dbfb06b6face041","repo":"dotnet/wpf","slug":"paragraphproperties-defaulttextrunproperties-typeface","errorCode":null,"errorMessage":"paragraphProperties.DefaultTextRunProperties.Typeface","messagePattern":"paragraphProperties\\.DefaultTextRunProperties\\.Typeface","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextFormatterImp.cs","lineNumber":454,"sourceCode":"        private void VerifyTextFormattingArguments(\n            TextSource                  textSource,\n            int                         firstCharIndex,\n            double                      paragraphWidth,\n            TextParagraphProperties     paragraphProperties,\n            TextRunCache                textRunCache\n            )\n        {\n            ArgumentNullException.ThrowIfNull(textSource);\n\n            ArgumentNullException.ThrowIfNull(textRunCache);\n\n            ArgumentNullException.ThrowIfNull(paragraphProperties);\n\n            if (paragraphProperties.DefaultTextRunProperties == null)\n                throw new ArgumentNullException(\"paragraphProperties.DefaultTextRunProperties\");\n\n            if (paragraphProperties.DefaultTextRunProperties.Typeface == null)\n                throw new ArgumentNullException(\"paragraphProperties.DefaultTextRunProperties.Typeface\");\n\n            ArgumentOutOfRangeException.ThrowIfEqual(paragraphWidth, double.NaN);\n            ArgumentOutOfRangeException.ThrowIfNegative(paragraphWidth);\n            ArgumentOutOfRangeException.ThrowIfEqual(paragraphWidth, double.PositiveInfinity);\n            ArgumentOutOfRangeException.ThrowIfGreaterThan(paragraphWidth, Constants.RealInfiniteWidth);\n\n            double realMaxFontRenderingEmSize = Constants.RealInfiniteWidth / Constants.GreatestMutiplierOfEm;\n\n            ArgumentOutOfRangeException.ThrowIfNegative(paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize, \"paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize\");\n            ArgumentOutOfRangeException.ThrowIfGreaterThan(paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize, realMaxFontRenderingEmSize, \"paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize\");\n            ArgumentOutOfRangeException.ThrowIfGreaterThan(paragraphProperties.Indent, Constants.RealInfiniteWidth, \"paragraphProperties.Indent\");\n            ArgumentOutOfRangeException.ThrowIfGreaterThan(paragraphProperties.LineHeight, Constants.RealInfiniteWidth, \"paragraphProperties.LineHeight\");\n            ArgumentOutOfRangeException.ThrowIfNegative(paragraphProperties.DefaultIncrementalTab, \"paragraphProperties.DefaultIncrementalTab\");\n            ArgumentOutOfRangeException.ThrowIfGreaterThan(paragraphProperties.DefaultIncrementalTab, Constants.RealInfiniteWidth, \"paragraphProperties.DefaultIncrementalTab\");\n        }\n\n\n        /// <summary>","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextFormatterImp.cs#L436-L472","documentation":"VerifyTextFormattingArguments also requires that DefaultTextRunProperties.Typeface is non-null. The typeface determines the default font used to measure and draw line content, so TextFormatter throws ArgumentNullException when it is missing.","triggerScenarios":"DefaultTextRunProperties is a valid object but its Typeface property is null when FormatLine/PrepareFormatSettings is invoked.","commonSituations":"Custom TextRunProperties implementations that return null Typeface; TextRunProperties clones/copies where the typeface field was not carried over; XML/JSON-derived font settings where the font name failed to resolve and was left null.","solutions":["Set the Typeface on the TextRunProperties instance passed as DefaultTextRunProperties","If building font info from a family name, use a resolved Typeface (e.g. new Typeface(\"Arial\")) rather than leaving it null","Validate DefaultTextRunProperties.Typeface before calling TextFormatter.FormatLine"],"exampleFix":"// before\nvar props = new TextRunProperties(); props.Typeface = null;\n// after\nvar props = new TextRunProperties(); props.Typeface = new Typeface(\"Arial\");","handlingStrategy":"validation","validationCode":"if (paragraphProperties?.DefaultTextRunProperties?.Typeface == null) throw new InvalidOperationException(\"DefaultTextRunProperties.Typeface must be set\");","typeGuard":"bool HasTypeface(TextParagraphProperties p) => p?.DefaultTextRunProperties?.Typeface != null;","tryCatchPattern":"try { formatter.FormatLine(...); } catch (ArgumentNullException) { /* set a Typeface on DefaultTextRunProperties */ }","preventionTips":["Always set a concrete Typeface on default run properties","Validate typeface resolution from family names (failed lookups can yield null)"],"tags":["wpf","text-formatting","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-21T21:30:21.729Z"}