dotnet/wpf · error · ArgumentException
SR.PropertyOfClassMustBeGreaterThanZero…
Error message
SR.PropertyOfClassMustBeGreaterThanZero (FontRenderingEmSize, TextRunProperties)
What it means
FetchTextRun requires FontRenderingEmSize to be strictly positive. It throws ArgumentException(SR.PropertyOfClassMustBeGreaterThanZero with FontRenderingEmSize/TextRunProperties) when the em size is zero or negative, since font size must be a positive real value to measure text.
Solutions
- Set FontRenderingEmSize to a positive value (e.g. > 0, at least 0.1) in your TextRunProperties
- Clamp computed font sizes to a small positive minimum before creating runs
- Validate run properties in your TextSource before returning the run
Example fix
// before props.FontRenderingEmSize = fontSize; // fontSize may be 0 // after props.FontRenderingEmSize = Math.Max(fontSize, 0.1);
Defensive patterns
Strategy: validation
Validate before calling
if (run.Properties == null || run.Properties.FontRenderingEmSize <= 0) throw new ArgumentException("FontRenderingEmSize must be > 0"); Type guard
bool HasValidEmSize(TextRun r) => r?.Properties?.FontRenderingEmSize > 0;
Try / catch
try { formatter.FormatLine(...); } catch (ArgumentException) { /* clamp em size and retry */ } Prevention
- Clamp computed font sizes to a positive minimum
- Guard zoom/scale math so size never reaches 0 or negative
When it happens
Trigger: TextRun.Properties.FontRenderingEmSize <= 0 returned by a TextSource; font size computed from data (e.g. zoom/scale) that collapsed to 0 or became negative.
Common situations: Zoom or scale factor of 0 applied to font size; uninitialized font size field defaulting to 0; data-binding producing NaN/0 sizes.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- PropertyOfClassCannotBeGreaterThan (FontRenderingEmSize…
- args
- args
- ArgumentOutOfRangeException(authenticationType)
- ArgumentOutOfRangeException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/3ec9fd7f87843852.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextRunCacheImp.cs:118
if(textRun == null)
{
// run not already cached, fetch new run and cache it
textRun = settings.TextSource.GetTextRun(cpFetch);
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(textRun.Length, "textRun.Length");
Plsrun plsrun = TextRunInfo.GetRunType(textRun);
if (plsrun == Plsrun.Text || plsrun == Plsrun.InlineObject)
{
TextRunProperties properties = textRun.Properties;
if (properties == null)
throw new ArgumentException(SR.TextRunPropertiesCannotBeNull);
if (properties.FontRenderingEmSize <= 0)
throw new ArgumentException(SR.Format(SR.PropertyOfClassMustBeGreaterThanZero, "FontRenderingEmSize", "TextRunProperties"));
double realMaxFontRenderingEmSize = Constants.RealInfiniteWidth / Constants.GreatestMutiplierOfEm;
if (properties.FontRenderingEmSize > realMaxFontRenderingEmSize)
throw new ArgumentException(SR.Format(SR.PropertyOfClassCannotBeGreaterThan, "FontRenderingEmSize", "TextRunProperties", realMaxFontRenderingEmSize));
CultureInfo culture = CultureMapper.GetSpecificCulture(properties.CultureInfo);
if (culture == null)
throw new ArgumentException(SR.Format(SR.PropertyOfClassCannotBeNull, "CultureInfo", "TextRunProperties"));
if (properties.Typeface == null)
throw new ArgumentException(SR.Format(SR.PropertyOfClassCannotBeNull, "Typeface", "TextRunProperties"));
}
//
// TextRun is specifial to SpanVector because TextRun also encodes position which needs to be View on GitHub (pinned to 81131a70a4)