dotnet/wpf · error · NotSupportedException

CollectionIsFixedSize

Error message

CollectionIsFixedSize

What it means

ThousandthOfEmRealPoints models an immutable, fixed-size point collection (like Point[]), so Add is explicitly unsupported and always throws NotSupportedException with SR.CollectionIsFixedSize. The collection is populated internally during text formatting, never by callers.

Solutions

  1. Do not mutate the collection; treat it as read-only and read values via CopyTo, indexer, or enumeration.
  2. Copy the points into your own List<Point> and modify that instead.
  3. If you need a different point set, construct a new collection/arrangement rather than appending.

Example fix

// before
collection.Add(new Point(x, y));
// after
var mutable = new List<Point>(collection);
mutable.Add(new Point(x, y));
Defensive patterns

Strategy: fallback

Validate before calling

if (collection.IsReadOnly) throw new InvalidOperationException("Collection is read-only; copy to a mutable list first.");

Type guard

// .NET
collection is ICollection<Point> c && !c.IsReadOnly

Try / catch

try { collection.Add(p); }
catch (NotSupportedException) { var list = new List<Point>(collection); list.Add(p); useList(list); }

Prevention

When it happens

Trigger: Calling Add(Point) on a ThousandthOfEmRealPoints instance, typically through the ICollection<Point> or IList<Point> interface in generic code.

Common situations: Generic algorithms that call ICollection<T>.Add when building collections, or LINQ-style bulk-fill code that assumes any ICollection is mutable.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/ThousandthOfEmRealPoints.cs:164

        }

        public IEnumerator<Point> GetEnumerator()
        {
            for (int i = 0; i < Count; i++)
            {
                yield return this[i];
            }
        }        

	System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return ((IEnumerable<Point>)this).GetEnumerator();
        }

        public void Add(Point value)
        {
            // not supported, same as Point[] 
            throw new NotSupportedException(SR.CollectionIsFixedSize);                           
        }

        public void Insert(int index, Point item)
        {
            // not supported, same as Point[] 
            throw new NotSupportedException(SR.CollectionIsFixedSize);                           
        }

        public bool Remove(Point item)
        {
            // not supported, same as Point[]             
            throw new NotSupportedException(SR.CollectionIsFixedSize);                           
        }

        public void RemoveAt(int index)
        {
            // not supported, same as Point[]             
            throw new NotSupportedException(SR.CollectionIsFixedSize);                           

View on GitHub (pinned to 81131a70a4)