{"record":{"id":"d9e8ce1f67af12c5","repo":"dotnet/wpf","slug":"sr-fontfamily-readonly","errorCode":null,"errorMessage":"SR.FontFamily_ReadOnly","messagePattern":"SR\\.FontFamily_ReadOnly","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FontFamily.cs","lineNumber":301,"sourceCode":"            }\n            else\n            {\n                // unnamed font families are equal only if they're the same instance\n                return base.Equals(o);\n            }\n        }\n\n\n        /// <summary>\n        /// Verifies that the FontFamily can be changed and returns a CompositeFontFamily\n        /// </summary>\n        private CompositeFontFamily VerifyMutable()\n        {\n            CompositeFontFamily mutableFamily = _firstFontFamily as CompositeFontFamily;\n\n            if (mutableFamily == null)\n            {\n                throw new NotSupportedException(SR.FontFamily_ReadOnly);\n            }\n\n            return mutableFamily;\n        }\n     \n\n        /// <summary>\n        /// First font family\n        /// </summary>\n        internal IFontFamily FirstFontFamily\n        {\n            get\n            {\n                IFontFamily family = _firstFontFamily;\n\n                if (family == null)\n                {\n                    // Call Canonicalize() directly so it won't just be called on the boxed object.","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FontFamily.cs#L283-L319","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","Guard with a check before setting, or skip the properties for simple families.","Define a composite font resource in XAML and reference it, so the family is mutable."],"exampleFix":"// before\nvar ff = new FontFamily(\"Arial\");\nff.Baseline = 0.9; // NotSupportedException\n// after\nvar ff = new FontFamily(new FontFamilyIdentifier(\"comic://composite\", null)); // composite-backed\nff.Baseline = 0.9;","handlingStrategy":"try-catch","validationCode":"// Skip mutation for simple families:\nbool isComposite = fontFamily.Source != null && fontFamily.FamilyNames.Count > 0; // heuristic; composite-backed families support Baseline/LineSpacing","typeGuard":null,"tryCatchPattern":"try { fontFamily.Baseline = value; }\ncatch (NotSupportedException) { /* simple family; property not supported */ }","preventionTips":["Only set Baseline/LineSpacing on families created from composite font definitions.","Check the family origin before applying metric overrides in templates or bindings.","Define composite font resources in XAML rather than mutating system families."],"tags":["wpf","fonts","notsupportedexception","readonly"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}