{"record":{"id":"89ce5873a8068eb6","repo":"dotnet/wpf","slug":"sr-general-objectisreadonly-familytypeface","errorCode":null,"errorMessage":"SR.General_ObjectIsReadOnly","messagePattern":"SR\\.General_ObjectIsReadOnly","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FamilyTypeface.cs","lineNumber":270,"sourceCode":"        public override bool Equals(object o)\n        {\n            return Equals(o as FamilyTypeface);\n        }\n\n        /// <summary>\n        /// <see cref=\"object.GetHashCode\"/>\n        /// </summary>\n        public override int GetHashCode()\n        {\n            return  _style.GetHashCode()\n                  ^ _weight.GetHashCode()\n                  ^ _stretch.GetHashCode();\n        }\n\n        private void VerifyChangeable()\n        {\n            if (_readOnly)\n                throw new NotSupportedException(SR.General_ObjectIsReadOnly);\n        }\n\n        string IDeviceFont.Name\n        {\n            get { return _deviceFontName; }\n        }\n\n        bool IDeviceFont.ContainsCharacter(int unicodeScalar)\n        {\n            return _characterMetrics != null && _characterMetrics.GetValue(unicodeScalar) != null;\n        }\n\n\n        unsafe void IDeviceFont.GetAdvanceWidths(\n            char*   characterString,\n            int     characterLength,\n            double  emSize,\n            int*    pAdvances","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FamilyTypeface.cs#L252-L288","documentation":"FamilyTypeface instances can be created read-only (_readOnly true), typically when they represent device font metrics returned from a composite font. VerifyChangeable throws NotSupportedException for any setter — Style, Weight, Stretch, UnderlinePosition, UnderlineThickness, StrikethroughPosition — on a read-only typeface.","triggerScenarios":"Setting any of Style, Weight, Stretch, UnderlinePosition, UnderlineThickness, or StrikethroughPosition on a FamilyTypeface whose _readOnly flag is set (e.g. a typeface obtained from the family's read-only typeface collection rather than a newly constructed one).","commonSituations":"Fetching a FamilyTypeface from FontFamily.FamilyTypefaces and trying to tweak its metrics in place, or modifying a typeface after it was contributed to a frozen/read-only composite font.","solutions":["Construct a new writable FamilyTypeface with new FontFamily(typeface) copy semantics, set the desired properties, and use that instance.","Copy all needed property values into a fresh FamilyTypeface before mutating.","If you own the creation path, keep a mutable instance and only hand out read-only copies to consumers."],"exampleFix":"// before\nvar tf = fontFamily.FamilyTypefaces[0];\ntf.Weight = FontWeights.Bold; // NotSupportedException\n// after\nvar tf = new FontFamily(fontFamily.FamilyTypefaces[0]); // writable copy\ntf.Weight = FontWeights.Bold;","handlingStrategy":"type-guard","validationCode":"// FamilyTypeface does not expose IsReadOnly; guard by only mutating instances you constructed yourself.","typeGuard":"static bool IsWritable(FamilyTypeface tf) => tf != null && !IsKnownReadOnlyInstance(tf); // track provenance; only new FamilyTypeface(...) instances are safely writable","tryCatchPattern":"try { tf.Weight = FontWeights.Bold; }\ncatch (NotSupportedException) { tf = new FamilyTypeface(tf) { Weight = FontWeights.Bold }; }","preventionTips":["Copy typefaces with new FamilyTypeface(existing) before editing.","Never mutate typefaces obtained from FontFamily.FamilyTypefaces.","Expose read-only instances only to readers."],"tags":["wpf","fonts","read-only","not-supported"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}