dotnet/wpf · error · NotSupportedException
This collection is fixed size.
Error message
This collection is fixed size.
What it means
PartialArray<T> is a fixed-size internal collection (IList<T> over a backing array segment); Remove throws NotSupportedException with the message 'This collection is fixed size.' because elements cannot be deleted once the array is allocated.
Solutions
- Do not call Remove; PartialArray is fixed-size by design — rebuild the collection without the item into a resizable List<T>.
- Copy the elements to a List<T> first and remove from that copy.
- Replace the data structure with List<T> if mutation is required.
Example fix
// before partialArray.Remove(item); // after var list = new List<T>(partialArray); list.Remove(item);
Defensive patterns
Strategy: type-guard
Validate before calling
if (coll.IsReadOnly || coll is System.Collections.Generic.ICollection<T> c && c.IsReadOnly) { /* skip mutation */ } Type guard
bool IsFixedSizeCollection<T>(ICollection<T> c) => c.IsReadOnly || c.GetType().Name == "PartialArray`1";
Try / catch
try { list.Remove(item); }
catch (NotSupportedException) { list = new List<T>(list); ((List<T>)list).Remove(item); } Prevention
- Check ICollection<T>.IsReadOnly before mutating an IList<T>/ICollection<T>.
- Copy to List<T> when generic code must mutate an unknown collection.
- Treat internal WPF collections as read-only views.
When it happens
Trigger: Calling Remove(item) — directly or via IList<T>/ICollection<T> interfaces — on any PartialArray instance.
Common situations: Generic code that treats any IList<T> as mutable and tries to remove an item, or internal WPF paths (e.g. glyph/character run collections) exposed through collection interfaces.
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
- CollectionIsFixedSize
- SR.CalendarCollection_MultiThreadedCollectionChangeNotSuppor…
- throw new NotSupportedException();
- throw new NotSupportedException() in IList
- By default, ToolTip property does not support ToolTip…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/b59f7849f2ca3a5c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/PartialArray.cs:61
}
}
public bool Contains(T item)
{
return IndexOf(item) >= 0;
}
public bool IsFixedSize
{
get
{
return true;
}
}
public bool Remove(T item)
{
throw new NotSupportedException(SR.CollectionIsFixedSize);
}
public void RemoveAt(int index)
{
throw new NotSupportedException(SR.CollectionIsFixedSize);
}
public void Clear()
{
throw new NotSupportedException();
}
public void Add(T item)
{
throw new NotSupportedException(SR.CollectionIsFixedSize);
}
public void Insert(int index, T item)View on GitHub (pinned to 81131a70a4)