{"record":{"id":"b59f7849f2ca3a5c","repo":"dotnet/wpf","slug":"this-collection-is-fixed-size","errorCode":null,"errorMessage":"This collection is fixed size.","messagePattern":"This collection is fixed size\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/PartialArray.cs","lineNumber":61,"sourceCode":"            }\n        }\n\n        public bool Contains(T item)\n        {\n            return IndexOf(item) >= 0;\n        }\n\n        public bool IsFixedSize\n        {\n            get\n            {\n                return true;\n            }\n        }\n\n        public bool Remove(T item)\n        {\n            throw new NotSupportedException(SR.CollectionIsFixedSize);                           \n        }\n\n        public void RemoveAt(int index)\n        {\n            throw new NotSupportedException(SR.CollectionIsFixedSize);                           \n        }\n\n        public void Clear()\n        {\n            throw new NotSupportedException();                           \n        }\n\n        public void Add(T item)\n        {\n            throw new NotSupportedException(SR.CollectionIsFixedSize);                           \n        }\n\n        public void Insert(int index, T item)","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/PartialArray.cs#L43-L79","documentation":"PartialArray<T> is a fixed-size internal collection (IList<T> over a backing array segment); Remove throws NotSupportedException with the message 'This collection is fixed size.' because elements cannot be deleted once the array is allocated.","triggerScenarios":"Calling Remove(item) — directly or via IList<T>/ICollection<T> interfaces — on any PartialArray instance.","commonSituations":"Generic code that treats any IList<T> as mutable and tries to remove an item, or internal WPF paths (e.g. glyph/character run collections) exposed through collection interfaces.","solutions":["Do not call Remove; PartialArray is fixed-size by design — rebuild the collection without the item into a resizable List<T>.","Copy the elements to a List<T> first and remove from that copy.","Replace the data structure with List<T> if mutation is required."],"exampleFix":"// before\npartialArray.Remove(item);\n// after\nvar list = new List<T>(partialArray);\nlist.Remove(item);","handlingStrategy":"type-guard","validationCode":"if (coll.IsReadOnly || coll is System.Collections.Generic.ICollection<T> c && c.IsReadOnly) { /* skip mutation */ }","typeGuard":"bool IsFixedSizeCollection<T>(ICollection<T> c) => c.IsReadOnly || c.GetType().Name == \"PartialArray`1\";","tryCatchPattern":"try { list.Remove(item); }\ncatch (NotSupportedException) { list = new List<T>(list); ((List<T>)list).Remove(item); }","preventionTips":["Check ICollection<T>.IsReadOnly before mutating an IList<T>/ICollection<T>.","Copy to List<T> when generic code must mutate an unknown collection.","Treat internal WPF collections as read-only views."],"tags":["wpf","collection","fixed-size","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"}