dotnet/wpf · error · ArgumentException

SR.Format(SR.PropertyValueCannotBeNaN, propertyName)

Error message

SR.Format(SR.PropertyValueCannotBeNaN, propertyName)

What it means

CompositeFontParser.VerifyMultiplierOfEm rejects NaN values for any em-relative multiplier property of a composite font. NaN cannot be meaningfully clamped or scaled, so it throws ArgumentException(SR.Format(SR.PropertyValueCannotBeNaN, propertyName)); finite values are clamped to Constants.GreatestMutiplierOfEm bounds.

Solutions

  1. Replace NaN in the composite font source with a valid finite multiplier (e.g. 1.0).
  2. Sanitize values before assignment: substitute a default when double.IsNaN(value).
  3. Fix the generator/exporter producing NaN attribute values.

Example fix

// before
map.ScaleInEm = double.NaN; // ArgumentException on verify
// after
map.ScaleInEm = double.IsNaN(v) ? 1.0 : v;
Defensive patterns

Strategy: validation

Validate before calling

if (double.IsNaN(value))
    throw new ArgumentException($"{propertyName} cannot be NaN.");
// or sanitize:
if (double.IsNaN(value)) value = 1.0;

Type guard

bool IsValidMultiplier(double v) => !double.IsNaN(v) && !double.IsInfinity(v);

Try / catch

try { CompositeFontParser.VerifyMultiplierOfEm(prop, ref value); }
catch (ArgumentException) { value = 1.0; /* default */ }

Prevention

When it happens

Trigger: Parsing a composite font (.CompositeFont XAML) where a multiplier attribute (e.g. Stretch, Bold, Scale on a FontFamilyMap, or similar em multiplier) is set to "NaN"/"Auto", triggering VerifyMultiplierOfEm with a NaN double.

Common situations: Hand-edited or tool-generated CompositeFont resources using NaN as a sentinel; data binding or computed values producing double.NaN before serialization; culture/parse issues yielding NaN from attribute text.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/e2176c3570e46e1e. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/CompositeFontParser.cs:25

using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Markup;
using System.Xml;
using System.Globalization;
using System.Collections;
using System.ComponentModel;
using MS.Internal.TextFormatting;

namespace MS.Internal.FontFace
{
    internal class CompositeFontParser
    {
        internal static void VerifyMultiplierOfEm(string propertyName, ref double value)
        {
            if (double.IsNaN(value))
            {
                throw new ArgumentException(SR.Format(SR.PropertyValueCannotBeNaN, propertyName));
            }
            else if (value > Constants.GreatestMutiplierOfEm)
            {
                value = Constants.GreatestMutiplierOfEm;
            }
            else if (value < -Constants.GreatestMutiplierOfEm)
            {
                value = -Constants.GreatestMutiplierOfEm;
            }
        }

        internal static void VerifyPositiveMultiplierOfEm(string propertyName, ref double value)
        {
            if (double.IsNaN(value))
            {
                throw new ArgumentException(SR.Format(SR.PropertyValueCannotBeNaN, propertyName));
            }
            else if (value > Constants.GreatestMutiplierOfEm)

View on GitHub (pinned to 81131a70a4)