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
- Do not mutate the collection; treat it as read-only and read values via CopyTo, indexer, or enumeration.
- Copy the points into your own List<Point> and modify that instead.
- 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
- Treat ThousandthOfEmRealPoints as immutable output of text formatting.
- Check ICollection<T>.IsReadOnly before mutating through the interface.
- Copy into List<Point> whenever modification is needed.
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
- 0x80040209
- Cannot remove signature from read-only file.
- Cannot sign read-only file.
- Image_OriginalStreamReadOnly
- NotSupportedException
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)