dotnet/wpf · error · ArgumentException

SR.Format(SR.PropertyCannotBeNegative, propertyName)

Error message

SR.Format(SR.PropertyCannotBeNegative, propertyName)

What it means

VerifyNonNegativeMultiplierOfEm throws ArgumentException when a composite font multiplier property is negative (but not NaN, which hits the earlier branch). Values above Constants.GreatestMutiplierOfEm are clamped; negative values are considered invalid data and fail the parse.

Solutions

  1. Set the attribute to a non-negative value (0 is allowed on this variant)
  2. Validate with v >= 0 before invoking the parser
  3. Re-deploy unmodified font resource files from source control

Example fix

<!-- before -->
<Family Scale="-0.5" />
<!-- after -->
<Family Scale="0.5" />
Defensive patterns

Strategy: validation

Validate before calling

if (value < 0) throw new ArgumentException($"{name} must be >= 0, got {value}");

Type guard

bool IsNonNegative(double v) => !double.IsNaN(v) && v >= 0;

Prevention

When it happens

Trigger: A .CompositeFont attribute such as a width, height, or scale factor is set to a negative number and the value flows through GetAttributeAsDouble into VerifyNonNegativeMultiplierOfEm.

Common situations: Typo in font family XML (e.g. Scale="-0.5"), corrupted resources after a bad merge or partial file copy, generated font definitions from faulty tooling.

Related errors


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

Appendix: source

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

            else if (value <= 0)
            {
                throw new ArgumentException(SR.Format(SR.PropertyMustBeGreaterThanZero, propertyName));
            }
        }

        internal static void VerifyNonNegativeMultiplierOfEm(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 < 0)
            {
                throw new ArgumentException(SR.Format(SR.PropertyCannotBeNegative, propertyName));
            }
        }

        private double GetAttributeAsDouble()
        {
            object value = null;

            try
            {
                value = _doubleTypeConverter.ConvertFromString(
                    null, // type converter context
                    System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS,
                    GetAttributeValue()
                    );
            }
            catch (NotSupportedException)
            {
                FailAttributeValue();

View on GitHub (pinned to 81131a70a4)