{"record":{"id":"086e3eb16d7503d8","repo":"dotnet/wpf","slug":"specified-method-is-not-supported","errorCode":null,"errorMessage":"Specified method is not supported.","messagePattern":"Specified method is not supported\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MultipleCopiesCollection.cs","lineNumber":300,"sourceCode":"                ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, RepeatCount);\n\n                Debug.Assert(_item != null, \"_item should be non-null.\");\n                return _item;\n            }\n\n            set\n            {\n                throw new InvalidOperationException();\n            }\n        }\n\n        #endregion\n\n        #region ICollection Members\n\n        public void CopyTo(Array array, int index)\n        {\n            throw new NotSupportedException();\n        }\n\n        public int Count\n        {\n            get { return RepeatCount; }\n        }\n\n        public bool IsSynchronized\n        {\n            get { return false; }\n        }\n\n        public object SyncRoot\n        {\n            get { return this; }\n        }\n\n        #endregion","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MultipleCopiesCollection.cs#L282-L318","documentation":"MultipleCopiesCollection implements ICollection.CopyTo by throwing NotSupportedException. Because the collection is just one item repeated RepeatCount times, copying is deliberately unimplemented; consumers should enumerate it instead.","triggerScenarios":"Calling CopyTo(array, index) directly, or indirectly via APIs that snapshot an ICollection (some LINQ-to-ICollection helpers, serialization, design-time tooling) on the cells presenter ItemsSource.","commonSituations":"Copying the generated cells collection to an array for analysis or testing; code that drains any ICollection into an Array.","solutions":["Enumerate with foreach / LINQ (Cast<object>().ToArray()) instead of CopyTo.","Copy the collection bound to DataGrid.ItemsSource, which is a normal collection.","Check IList.IsReadOnly/IsFixedSize before using CopyTo-based generic helpers."],"exampleFix":"// before\n((ICollection)presenter.ItemsSource).CopyTo(arr, 0);\n\n// after\nvar arr = presenter.ItemsSource.Cast<object>().ToArray();","handlingStrategy":"fallback","validationCode":"var items = itemsSource is IEnumerable e ? e.Cast<object>().ToArray() : Array.Empty<object>();","typeGuard":"bool SupportsCopyTo(object c) => c is ICollection col && !(c is System.Windows.Controls.MultipleCopiesCollection);","tryCatchPattern":"try { col.CopyTo(arr, 0); }\ncatch (NotSupportedException) { arr = col.Cast<object>().ToArray(); }","preventionTips":["Use foreach/LINQ enumeration instead of CopyTo for UI-generated collections","Snapshot with ToList() before processing"],"tags":["wpf","datagrid","read-only-collection","notsupportedexception"],"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"}