dotnet/wpf · error · NotSupportedException

SR.FontFamily_ReadOnly

Error message

SR.FontFamily_ReadOnly

What it means

FontFamily.VerifyMutable throws this NotSupportedException when _firstFontFamily is not a CompositeFontFamily, meaning the FontFamily was created from a simple family name and has no modifiable composite-font data. Baseline and LineSpacing setters call VerifyMutable because those properties only exist on composite font families.

Solutions

  1. Only set Baseline/LineSpacing on FontFamily instances created from a composite font (e.g. loaded from a FONT_FAMILY/composite definition with multiple family entries).
  2. Guard with a check before setting, or skip the properties for simple families.
  3. Define a composite font resource in XAML and reference it, so the family is mutable.

Example fix

// before
var ff = new FontFamily("Arial");
ff.Baseline = 0.9; // NotSupportedException
// after
var ff = new FontFamily(new FontFamilyIdentifier("comic://composite", null)); // composite-backed
ff.Baseline = 0.9;
Defensive patterns

Strategy: try-catch

Validate before calling

// Skip mutation for simple families:
bool isComposite = fontFamily.Source != null && fontFamily.FamilyNames.Count > 0; // heuristic; composite-backed families support Baseline/LineSpacing

Try / catch

try { fontFamily.Baseline = value; }
catch (NotSupportedException) { /* simple family; property not supported */ }

Prevention

When it happens

Trigger: Setting FontFamily.Baseline or FontFamily.LineSpacing on a FontFamily constructed from a plain name like new FontFamily("Arial"), rather than from a composite font definition.

Common situations: Attempting to tweak baseline metrics on a system font family at runtime, or a data-binding/template that sets these properties regardless of the family kind.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FontFamily.cs:301

            }
            else
            {
                // unnamed font families are equal only if they're the same instance
                return base.Equals(o);
            }
        }


        /// <summary>
        /// Verifies that the FontFamily can be changed and returns a CompositeFontFamily
        /// </summary>
        private CompositeFontFamily VerifyMutable()
        {
            CompositeFontFamily mutableFamily = _firstFontFamily as CompositeFontFamily;

            if (mutableFamily == null)
            {
                throw new NotSupportedException(SR.FontFamily_ReadOnly);
            }

            return mutableFamily;
        }
     

        /// <summary>
        /// First font family
        /// </summary>
        internal IFontFamily FirstFontFamily
        {
            get
            {
                IFontFamily family = _firstFontFamily;

                if (family == null)
                {
                    // Call Canonicalize() directly so it won't just be called on the boxed object.

View on GitHub (pinned to 81131a70a4)