stride3d/stride · error · ArgumentOutOfRangeException
ArgumentOutOfRangeException
Error message
ArgumentOutOfRangeException
What it means
VisualScriptViewModel.MethodsContentChanged reacts to collection-change events on the Methods collection and switches on the change action. Any action it does not explicitly handle (e.g. Reset, Move, Replace, or an Add case missing from this handler) falls through to `throw new ArgumentOutOfRangeException()`. The message is empty because the exception is used purely as an unhandled-case guard.
Solutions
- Avoid operations that emit Reset on Methods while this handler is subscribed; clear methods individually instead of Clear().
- Extend the switch in MethodsContentChanged to handle Reset/Move/Replace actions explicitly.
- Validate e.Index before indexing (skip or rebuild when Index is None/-1, as with Reset).
- Check for competing writers to Methods (multiple subscriptions or background threads) and serialize the mutations.
Example fix
// before
throw new ArgumentOutOfRangeException();
// after
case NotifyCollectionChangedAction.Reset:
RebuildMethodViewModels();
break;
default:
Log.Warning("Unhandled collection action: {Action}", e.Action);
break; Defensive patterns
Strategy: try-catch
Validate before calling
if (e.Action == NotifyCollectionChangedAction.Reset) { RebuildMethodViewModels(); return; }
if (e.NewStartingIndex < 0 || e.NewStartingIndex >= Methods.Count) return; Try / catch
try
{
var vm = Methods[e.Index.Int];
vm?.Destroy();
Methods.RemoveAt(e.Index.Int);
}
catch (ArgumentOutOfRangeException)
{
RebuildMethodViewModels(); // resync view models with the collection
} Prevention
- Handle Reset/Move/Replace explicitly instead of relying on a default throw.
- Avoid Clear() on observed collections; remove items individually.
- Guard all e.Index accesses against NotifyCollectionChangedAction.Reset (Index is -1).
When it happens
Trigger: Raising a NotifyCollectionChangedAction on the Methods collection other than the handled actions (e.g. Reset from Clear(), Move, Replace, or Add/Remove with an out-of-range e.Index such as Reset, whose Index is -1 while the Remove branch does Methods[e.Index.Int]).
Common situations: Calling Methods.Clear() (produces Reset) from custom editor code; bulk-loading methods with a Replace/Reset notification; index mismatches after the collection changed elsewhere between the event and the handler; data-binding operations firing Move.
Related errors
- SourceFolder.Folder cannot be null
- There must be four and only four input values for Color.
- 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/7abc81b48855450f.
Report an issue: GitHub.
Appendix: source
Thrown at sources/editor/Stride.Assets.Presentation/ViewModel/VisualScriptViewModel.cs:99
{
switch (e.ChangeType)
{
case ContentChangeType.None:
case ContentChangeType.CollectionAdd:
{
var function = (Method)e.NewValue;
Methods.Insert(e.Index.Int, new VisualScriptMethodViewModel(this, function));
break;
}
case ContentChangeType.CollectionRemove:
{
var viewModel = Methods[e.Index.Int];
viewModel?.Destroy();
Methods.RemoveAt(e.Index.Int);
break;
}
default:
throw new ArgumentOutOfRangeException();
}
}
}
}
View on GitHub (pinned to 96fad776d2)