dotnet/wpf · error · NotImplementedException

NotImplementedException

Error message

NotImplementedException

What it means

LiveShapingList's explicit ICollection.CopyTo implementation is intentionally unimplemented and always throws NotImplementedException. LiveShapingList is an internal WPF structure backing live-shaping CollectionViews, and array-copy via the ICollection interface is not a supported path.

Solutions

  1. Enumerate the list with IEnumerable (foreach) instead of CopyTo.
  2. Copy the view contents from the public surface instead: use the CollectionView's Items or OfType<object>().ToArray().
  3. If a copy is truly required, build it manually: var arr = list.Cast<object>().ToArray().

Example fix

// before
((ICollection)liveShapingList).CopyTo(target, 0); // NotImplementedException

// after
var items = liveShapingList.Cast<object>().ToArray();
Defensive patterns

Strategy: fallback

Validate before calling

// prefer enumeration; ICollection.CopyTo on LiveShapingList is unimplemented
var items = list is System.Collections.IEnumerable e ? e.Cast<object>().ToArray() : new object[0];

Type guard

static bool SupportsCopyTo(System.Collections.ICollection c) => !(c.GetType().Name == "LiveShapingList");

Try / catch

try { ((System.Collections.ICollection)list).CopyTo(arr, 0); }
catch (NotImplementedException) { var items = list.Cast<object>().ToArray(); }

Prevention

When it happens

Trigger: Calling CopyTo (directly or via ICollection/System.Collections casts, LINQ's CopyTo-based helpers, or ArrayList/Array.Copy patterns) on a LiveShapingList instance obtained through internal CollectionView plumbing.

Common situations: Code that reflects into WPF's CollectionView internals (e.g. to dump view contents) and treats the inner live-shaping list as a plain ICollection; custom sorting/paging utilities that enumerate via ICollection.CopyTo.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/cc2bf375579dcd81. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/LiveShapingList.cs:617

        public int GetCopies()
        {
            return _root.GetCopies();
        }

        public double GetAverageCopy()
        {
            return _root.GetAverageCopy();
        }

        int _comparisons;

#endif // LiveShapingInstrumentation

        #region ICollection Members

        public void CopyTo(Array array, int index)
        {
            throw new NotImplementedException();
        }

        public int Count
        {
            get { return _root.Count; }
        }

        public bool IsSynchronized
        {
            get { return false; }
        }

        public object SyncRoot
        {
            get { return null; }
        }

        #endregion

View on GitHub (pinned to 81131a70a4)