stride3d/stride · error · ArgumentException
Provided collections don't match an existing scope
Error message
Provided collections don't match an existing scope
What it means
UnregisterSelectionScope iterates the registered scopes looking for one whose tracked collections match the supplied collections; if none matches, it throws ArgumentException stating the provided collections don't match an existing scope.
Solutions
- Keep and pass the exact same collection instances used at RegisterSelectionScope time
- Register the scope before attempting to unregister; skip unregister if never registered
- Make unregister idempotent by checking registration state first
Example fix
// before
selectionService.UnregisterSelectionScope(items); // items is a reconstructed collection
// after
if (registeredCollections != null)
selectionService.UnregisterSelectionScope(registeredCollections); // same reference as registered Defensive patterns
Strategy: validation
Validate before calling
if (registeredScopes.All(s => !s.Collections.SequenceEqual(collections))) return; // not registered; nothing to unregister
Type guard
bool IsScopeRegistered(IEnumerable<object> collections) => /* check against the service's registered scope collections */ false;
Try / catch
try { selectionService.UnregisterSelectionScope(collections); } catch (ArgumentException) { /* scope never registered or already removed; ignore */ } Prevention
- Store the original collection references used at registration and reuse them for unregistration
- Make unregister calls idempotent and guarded
- Avoid LINQ projections/copies when passing collections to scope APIs
When it happens
Trigger: Calling UnregisterSelectionScope with a collection (or collection set) that was never registered via RegisterSelectionScope, or with a copy/rebuilt collection instance that no longer matches the registered reference, or after the scope was already unregistered.
Common situations: Double-unregister on teardown; passing a LINQ-enumerated copy instead of the original collection; view recreated (new collection instances) while the old scope registration held the originals.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- A session is already open in this instance.
- An asset [ ] with the same location [ ] is already…
- An asset with the same id
- Anchor value must contain alphanumerical characters only.
- Anchor value must not be empty.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/480713a6d4e20cd0.
Report an issue: GitHub.
Appendix: source
Thrown at sources/editor/Stride.Core.Assets.Editor/Services/SelectionService.cs:136
}
/// <summary>
/// Unregisters collections of selected objects from the <see cref="SelectionService"/>.
/// </summary>
/// <param name="collections"></param>
/// <remarks>The order of the collections to unregister must match the order used when registering with <see cref="RegisterSelectionScope"/>.</remarks>
public void UnregisterSelectionScope(params INotifyCollectionChanged[] collections)
{
foreach (var scope in scopes)
{
if (ArrayExtensions.ArraysReferenceEqual(scope.Collections, collections))
{
UnregisterSelectionScope(scope);
return;
}
}
throw new ArgumentException($"Provided {nameof(collections)} don't match an existing scope", nameof(collections));
}
/// <summary>
/// Unregisters a collection scope selected objects from the <see cref="SelectionService"/>.
/// </summary>
/// <param name="scope">The selection scope to unregister.</param>
public void UnregisterSelectionScope([NotNull] SelectionScope scope)
{
if (scope == null) throw new ArgumentNullException(nameof(scope));
foreach (var collection in scope.Collections)
collection.CollectionChanged -= CollectionChanged;
scopes.Remove(scope);
// Update history to let it know about this collection
foreach (var operation in stack.RetrieveAllTransactions().SelectMany(x => x.Operations).OfType<SelectionOperation>())
{
foreach (var collection in scope.Collections)
operation.UnregisterCollection(collection);
}View on GitHub (pinned to 96fad776d2)