{"record":{"id":"19c4099ceee5edd2","repo":"dotnet/wpf","slug":"sr-general-objectisreadonly-familytypefacecollection","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/FamilyTypefaceCollection.cs","lineNumber":350,"sourceCode":"                for (int i = 0; i < _count; ++i)\n                {\n                    if (GetItem(i).Equals(item))\n                        return i;\n                }\n            }\n            return -1;\n        }\n\n        private void RangeCheck(int index)\n        {\n            ArgumentOutOfRangeException.ThrowIfNegative(index);\n            ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, _count);\n        }\n\n        private void VerifyChangeable()\n        {\n            if (_innerList != null)\n                throw new NotSupportedException(SR.General_ObjectIsReadOnly);\n        }\n\n        private FamilyTypeface ConvertValue(object obj)\n        {\n            ArgumentNullException.ThrowIfNull(obj);\n\n            FamilyTypeface familyTypeface = obj as FamilyTypeface;\n            if (familyTypeface == null)\n                throw new ArgumentException(SR.Format(SR.CannotConvertType, obj.GetType(), typeof(FamilyTypeface)));\n\n            return familyTypeface;\n        }\n\n        private void CopyItems(Array array, int index)\n        {\n            ArgumentNullException.ThrowIfNull(array);\n\n            if (array.Rank != 1)","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FamilyTypefaceCollection.cs#L332-L368","documentation":"FamilyTypefaceCollection becomes read-only when _innerList is non-null — it then wraps a fixed list of FamilyTypeface objects (e.g. a family's existing typefaces). VerifyChangeable throws NotSupportedException for any mutating call: Remove, Insert, SetItem, Clear, RemoveAt.","triggerScenarios":"Calling Add, Insert, Remove, RemoveAt, Clear, or the set indexer on a FamilyTypefaceCollection constructed with an inner list (read-only mode), e.g. FontFamily.FamilyTypefaces of a family backed by an existing typeface list.","commonSituations":"Trying to modify the typeface collection of an installed/system font family at runtime instead of defining your own composite font.","solutions":["Do not mutate the wrapped collection; build a new FamilyTypefaceCollection in changeable mode and add typefaces there.","Create a new FontFamily with a composite font definition containing your typefaces.","If you construct the collection yourself, use the changeable constructor (no inner list)."],"exampleFix":"// before\nfontFamily.FamilyTypefaces.Clear(); // NotSupportedException\n// after\nvar newCollection = new FamilyTypefaceCollection(); // changeable, no inner list\nnewCollection.Add(new FamilyTypeface { Weight = FontWeights.Bold });","handlingStrategy":"validation","validationCode":"// Collection backed by an inner list is read-only; only mutate collections you constructed without an inner list.","typeGuard":"static bool IsChangeable(FamilyTypefaceCollection c) => c != null && IsChangeableInstance(c); // prefer constructing your own collection for mutation","tryCatchPattern":"try { collection.Add(tf); }\ncatch (NotSupportedException ex) { /* read-only collection; build a new one */ }","preventionTips":["Treat FontFamily.FamilyTypefaces as read-only.","Create a new FamilyTypefaceCollection for custom composite fonts.","Do not attempt in-place edits of system font family typeface lists."],"tags":["wpf","fonts","read-only-collection","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-22T01:17:13.364Z"}