stride3d/stride · error · ArgumentOutOfRangeException
ArgumentOutOfRangeException
Error message
ArgumentOutOfRangeException
What it means
The default branch of the switch in SceneViewModel.ChildrenCollectionChanged throws ArgumentOutOfRangeException when the NotifyCollectionChangedAction is not one of the explicitly handled values. This is a defensive guard: the enum value received is outside the set {Replace, Add, Remove, Move, Reset}.
Solutions
- Fix the collection implementation or cast that produces an invalid NotifyCollectionChangedAction value.
- Add a diagnostic log of e.Action in the default branch to identify the offending event source.
- Handle the unknown action defensively (rebuild childrenNode from current state) instead of throwing.
Example fix
// before
case NotifyCollectionChangedAction.Reset:
throw new NotSupportedException();
default:
throw new ArgumentOutOfRangeException();
// after
case NotifyCollectionChangedAction.Reset:
throw new NotSupportedException();
default:
throw new InvalidOperationException($"Unexpected NotifyCollectionChangedAction: {e.Action}"); Defensive patterns
Strategy: validation
Validate before calling
if (!Enum.IsDefined(typeof(NotifyCollectionChangedAction), e.Action))
return; // invalid enum value, skip instead of crashing Type guard
static bool IsValidAction(NotifyCollectionChangedAction a) =>
a is >= NotifyCollectionChangedAction.Add and <= NotifyCollectionChangedAction.Reset; Try / catch
try { handler(sender, e); }
catch (ArgumentOutOfRangeException ex)
{
logger.Warning($"Unknown NotifyCollectionChangedAction from {sender}: {ex.Message}");
} Prevention
- Only subscribe to well-known INotifyCollectionChanged implementations.
- Avoid int-to-enum casts when raising CollectionChanged events.
- After Stride upgrades, re-check switch statements over enums for new members.
When it happens
Trigger: CollectionChanged raised with an invalid or unrecognized NotifyCollectionChangedAction value (e.g. a cast of an arbitrary int into the enum), reaching the default: branch.
Common situations: Buggy custom collection implementations or unsafe casts producing undefined enum values; essentially never hit with a standard ObservableCollection, but possible with hand-rolled INotifyCollectionChanged sources.
Related errors
- Specified argument was out of the range of valid values…
- Specified argument was out of the range of valid values…
- Indices for Color run from 0 to 3, inclusive.
- There must be three and only three input values for Color3.
- Indices for Color3 run from 0 to 2, inclusive.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/c8773c969bf24a5d.
Report an issue: GitHub.
Appendix: source
Thrown at sources/editor/Stride.Assets.Presentation/ViewModel/SceneViewModel.cs:279
var index = e.NewStartingIndex;
foreach (var scene in e.NewItems.Cast<SceneViewModel>())
{
// Note: this can happen after a cut/paste when the parent/child relationship is fixed-up.
if (scene.Parent != this)
{
scene.Parent?.Children.Remove(scene);
scene.Parent = this;
}
childrenNode.Add(scene.Id, new NodeIndex(index++));
}
}
break;
case NotifyCollectionChangedAction.Move:
case NotifyCollectionChangedAction.Reset:
throw new NotSupportedException();
default:
throw new ArgumentOutOfRangeException();
}
}
finally
{
updatingChildren = false;
}
}
private void ChildrenNodeItemChanged(object sender, ItemChangeEventArgs e)
{
if (updatingChildren)
return;
try
{
updatingChildren = true;
switch (e.ChangeType)
{View on GitHub (pinned to 96fad776d2)