{"record":{"id":"7581c65a682a4bb8","repo":"dotnet/wpf","slug":"collectionisfixedsize","errorCode":null,"errorMessage":"CollectionIsFixedSize","messagePattern":"CollectionIsFixedSize","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/ThousandthOfEmRealDoubles.cs","lineNumber":220,"sourceCode":"\n        public IEnumerator<double> GetEnumerator()\n        {\n            for (int i = 0; i < Count; i++)\n            {\n                yield return this[i];\n            }\n        }        \n\n\tSystem.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()\n        {\n            return ((IEnumerable<double>)this).GetEnumerator();\n        }\n\n\n        public void Add(double value)\n        {\n            // not supported, same as double[] \n            throw new NotSupportedException(SR.CollectionIsFixedSize);                           \n        }\n\n        public void Insert(int index, double item)\n        {\n            // not supported, same as double[] \n            throw new NotSupportedException(SR.CollectionIsFixedSize);                           \n        }\n\n        public bool Remove(double item)\n        {\n            // not supported, same as double[]             \n            throw new NotSupportedException(SR.CollectionIsFixedSize);                           \n        }\n\n        public void RemoveAt(int index)\n        {\n            // not supported, same as double[]             \n            throw new NotSupportedException(SR.CollectionIsFixedSize);                           ","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/ThousandthOfEmRealDoubles.cs#L202-L238","documentation":"ThousandthOfEmRealDoubles.Add throws NotSupportedException(SR.CollectionIsFixedSize). The collection is a fixed-size wrapper (like double[]) — it models a read-only-size sequence of glyph-metric doubles, so mutation via Add is deliberately unsupported.","triggerScenarios":"Calling Add(double) directly or through ICollection<double>/IList interfaces, e.g. ((ICollection<double>)collection).Add(0.5).","commonSituations":"Generic algorithms that treat any ICollection<T> as growable; LINQ/buffer-copying code paths that append; porting code that used List<double>.","solutions":["Do not mutate; construct a new ThousandthOfEmRealDoubles with the required capacity and populate via the constructor/init path","Use List<double> (or double[]) if you need Add semantics, then create the collection from it","CheckICollection<double>.IsFixedSize before attempting mutation in generic code"],"exampleFix":"// before\ncollection.Add(0.25);\n// after\nvar list = new List<double>(collection) { 0.25 };\nvar fixedCollection = new ThousandthOfEmRealDoubles(list, 0);","handlingStrategy":"type-guard","validationCode":"if (((ICollection<double>)collection).IsFixedSize)\n    throw new InvalidOperationException(\"collection does not support Add\");","typeGuard":"static bool SupportsAdd(ICollection<double> c) => !c.IsFixedSize;","tryCatchPattern":"try { ((ICollection<double>)collection).Add(v); }\ncatch (NotSupportedException ex)\n{ /* rebuild collection with new capacity instead */ }","preventionTips":["Treat ThousandthOfEmRealDoubles as immutable/fixed-size like double[]","In generic code, check IsFixedSize before mutating ICollection<T>","Use List<double> for growable scenarios and build the collection at the end"],"tags":["wpf","collections","not-supported","fixed-size"],"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"}