dotnet/wpf · error · NotSupportedException
SR.RangeActionsNotSupported
Error message
SR.RangeActionsNotSupported
What it means
DocumentSequenceTextContainer._OnContentChanged handles CollectionChanged from the sequence's References. Add events must contain exactly one item; a multi-item (range) Add is not supported by the incremental ChildDocumentBlock bookkeeping, so NotSupportedException with RangeActionsNotSupported is thrown.
Solutions
- Add DocumentReference items one at a time so each Add event carries a single item
- Replace bulk AddRange with a loop of individual Add calls
- If you own the collection, never batch NotifyCollectionChangedAction.Add with multiple NewItems
Example fix
// before
references.AddRange(newDocs); // single Add event, count != 1
// after
foreach (var d in newDocs) { references.Add(d); } Defensive patterns
Strategy: validation
Validate before calling
if (args.Action == NotifyCollectionChangedAction.Add && args.NewItems.Count != 1)
throw new NotSupportedException("DocumentSequence.References supports single-item Add only"); Type guard
bool IsSingleItemAdd(NotifyCollectionChangedEventArgs a) => a.Action == NotifyCollectionChangedAction.Add && a.NewItems?.Count == 1;
Try / catch
try { references.AddRange(items); }
catch (NotSupportedException) { foreach (var i in items) references.Add(i); } Prevention
- Never batch-add multiple DocumentReferences in one event
- Replace AddRange with per-item Add loops
- Keep References a simple ObservableCollection with single-item notifications
When it happens
Trigger: Adding multiple DocumentReference items to DocumentSequence.References in one CollectionChanged event (e.g., AddRange or a collection that batches adds).
Common situations: Custom ObservableCollection subclass that raises one Add event with several new items; batch-loading child documents into a FixedDocumentSequence via a bulk-add helper.
Related errors
- SR.Format(SR.UnexpectedCollectionChangeAction, args.Action)
- SR.Format(SR.UnexpectedCollectionChangeAction, args.Action)
- args
- Collection_CopyTo_ArrayCannotBeMultidimensional
- Collection_CopyTo_ArrayCannotBeMultidimensional
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ca71593b407d5bff.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentSequenceTextContainer.cs:595
{
textContainer.EndChange();
}
}
//--------------------------------------------------------------------
// ContentChange
//---------------------------------------------------------------------
private void _OnContentChanged(object sender, NotifyCollectionChangedEventArgs args)
{
#if DEBUG
this._generation++;
#endif
if (args.Action == NotifyCollectionChangedAction.Add)
{
if (args.NewItems.Count != 1)
{
throw new NotSupportedException(SR.RangeActionsNotSupported);
}
else
{
object item = args.NewItems[0];
int startingIndex = args.NewStartingIndex;
if (startingIndex != _parent.References.Count - 1)
{
throw new NotSupportedException(SR.Format(SR.UnexpectedCollectionChangeAction, args.Action));
}
ChildDocumentBlock newBlock = new ChildDocumentBlock(this, (DocumentReference)item);
ChildDocumentBlock insertAfter = _doclistTail.PreviousBlock;
insertAfter.InsertNextBlock(newBlock);
DocumentSequenceTextPointer changeStart =
new DocumentSequenceTextPointer(insertAfter, insertAfter.End);
View on GitHub (pinned to 81131a70a4)