dotnet/wpf · error · ArgumentNullException
paragraphProperties.DefaultTextRunProperties
Error message
paragraphProperties.DefaultTextRunProperties
What it means
TextFormatterImp.VerifyTextFormattingArguments validates arguments to FormatLine/FormatParagraph. It throws ArgumentNullException when TextParagraphProperties.DefaultTextRunProperties is null. The library requires default run properties on the paragraph properties because they supply the typeface and font metrics used for line formatting.
Solutions
- Set DefaultTextRunProperties to a valid TextRunProperties instance (e.g. a new TextRunProperties or SimpleTextProps) in your TextParagraphProperties implementation
- Check your custom TextParagraphProperties constructor for a missing DefaultTextRunProperties assignment
- Throw your own ArgumentNullException in your paragraph-properties constructor to catch this at construction time
Example fix
// before
public class MyParaProps : TextParagraphProperties { /* never set DefaultTextRunProperties */ }
// after
public class MyParaProps : TextParagraphProperties {
public MyParaProps() {
DefaultTextRunProperties = new SimpleTextProps(typeface, 12.0); // must be non-null
}
} Defensive patterns
Strategy: validation
Validate before calling
if (paragraphProperties == null) throw new ArgumentNullException(nameof(paragraphProperties));
if (paragraphProperties.DefaultTextRunProperties == null) throw new ArgumentNullException("DefaultTextRunProperties"); Type guard
bool IsValidParaProps(TextParagraphProperties p) => p?.DefaultTextRunProperties != null;
Try / catch
try { formatter.FormatLine(...); } catch (ArgumentNullException) { /* supply valid DefaultTextRunProperties and retry */ } Prevention
- Always initialize DefaultTextRunProperties in TextParagraphProperties constructors
- Assert non-null DefaultTextRunProperties before calling TextFormatter APIs
When it happens
Trigger: Calling TextFormatter.FormatLine (via PrepareFormatSettings) with a TextParagraphProperties subclass whose DefaultTextRunProperties was never set (left null in the constructor or manually assigned null).
Common situations: Custom TextParagraphProperties implementations where the constructor forgot to initialize DefaultTextRunProperties; refactoring that removed the TextRunProperties assignment; passing a default-constructed paragraph properties object.
Related errors
- paragraphProperties.DefaultTextRunProperties.Typeface
- annotation component
- ArgumentNullException
- ArgumentNullException(argName)
- ArgumentNullException("characterBufferReference.CharacterBuf…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/809e1ab503190573.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextFormatterImp.cs:451
/// <summary>
/// Verify all text formatting arguments
/// </summary>
private void VerifyTextFormattingArguments(
TextSource textSource,
int firstCharIndex,
double paragraphWidth,
TextParagraphProperties paragraphProperties,
TextRunCache textRunCache
)
{
ArgumentNullException.ThrowIfNull(textSource);
ArgumentNullException.ThrowIfNull(textRunCache);
ArgumentNullException.ThrowIfNull(paragraphProperties);
if (paragraphProperties.DefaultTextRunProperties == null)
throw new ArgumentNullException("paragraphProperties.DefaultTextRunProperties");
if (paragraphProperties.DefaultTextRunProperties.Typeface == null)
throw new ArgumentNullException("paragraphProperties.DefaultTextRunProperties.Typeface");
ArgumentOutOfRangeException.ThrowIfEqual(paragraphWidth, double.NaN);
ArgumentOutOfRangeException.ThrowIfNegative(paragraphWidth);
ArgumentOutOfRangeException.ThrowIfEqual(paragraphWidth, double.PositiveInfinity);
ArgumentOutOfRangeException.ThrowIfGreaterThan(paragraphWidth, Constants.RealInfiniteWidth);
double realMaxFontRenderingEmSize = Constants.RealInfiniteWidth / Constants.GreatestMutiplierOfEm;
ArgumentOutOfRangeException.ThrowIfNegative(paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize, "paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize");
ArgumentOutOfRangeException.ThrowIfGreaterThan(paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize, realMaxFontRenderingEmSize, "paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize");
ArgumentOutOfRangeException.ThrowIfGreaterThan(paragraphProperties.Indent, Constants.RealInfiniteWidth, "paragraphProperties.Indent");
ArgumentOutOfRangeException.ThrowIfGreaterThan(paragraphProperties.LineHeight, Constants.RealInfiniteWidth, "paragraphProperties.LineHeight");
ArgumentOutOfRangeException.ThrowIfNegative(paragraphProperties.DefaultIncrementalTab, "paragraphProperties.DefaultIncrementalTab");
ArgumentOutOfRangeException.ThrowIfGreaterThan(paragraphProperties.DefaultIncrementalTab, Constants.RealInfiniteWidth, "paragraphProperties.DefaultIncrementalTab");
}View on GitHub (pinned to 81131a70a4)