stride3d/stride · error · ArgumentException
index cannot be Index.Empty when invoking this method.
Error message
index cannot be Index.Empty when invoking this method.
What it means
IndexedTarget(NodeIndex) resolves the target node of an item reference stored on this ObjectNode. NodeIndex.Empty is a sentinel meaning 'no index' and cannot identify an item reference, so the method guards against it with ArgumentException. Callers must supply the concrete NodeIndex of the collection item they want to dereference.
Solutions
- Only call IndexedTarget with a real item NodeIndex obtained from the node's children/index enumeration
- Check 'if (index == NodeIndex.Empty) return null;' before calling when the index may be unset
- Ensure the value came from an actual item lookup (e.g. NodeContainer item events provide valid indices)
- If the target is a member rather than an indexed item, use the indexer/Member API instead of IndexedTarget
Example fix
// before
var target = node.IndexedTarget(NodeIndex.Empty); // throws
// after
if (index != NodeIndex.Empty)
var target = node.IndexedTarget(index); Defensive patterns
Strategy: validation
Validate before calling
if (index == NodeIndex.Empty) return null; // or throw with context before calling
Type guard
static bool HasValidIndex(NodeIndex i) => i != NodeIndex.Empty;
Try / catch
try { target = node.IndexedTarget(index); }
catch (ArgumentException ex) when (ex.ParamName == "index")
{ /* index was NodeIndex.Empty — treat as no target */ } Prevention
- Always obtain NodeIndex values from node children or item events, never default them
- Initialize NodeIndex fields explicitly and check for NodeIndex.Empty before dereferencing
- Use the member API (this[string]) for named access instead of indexed access
When it happens
Trigger: Calling IndexedTarget(NodeIndex.Empty) — typically when an index variable was never assigned, an optional index defaulted to NodeIndex.Empty, or an item-less node was queried.
Common situations: Iterating collection items with an uninitialized NodeIndex; calling IndexedTarget on a member node rather than an indexed item; propagating NodeIndex.Empty from a failed lookup instead of short-circuiting.
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
- An ObjectNode cannot contain an ObjectReference
- The node does not contain enumerable references.
- Could not find dependency
- This parameter must be a formattable string containing
- Value type for root objects are not supported
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/61330c7fb5a3764b.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Quantum/ObjectNode.cs:75
public event EventHandler<INodeChangeEventArgs>? FinalizeChange;
/// <inheritdoc/>
public event EventHandler<ItemChangeEventArgs>? ItemChanging;
/// <inheritdoc/>
public event EventHandler<ItemChangeEventArgs>? ItemChanged;
/// <inheritdoc/>
public IMemberNode? TryGetChild(string name)
{
childrenMap.TryGetValue(name, out var child);
return child;
}
/// <inheritdoc/>
public IObjectNode? IndexedTarget(NodeIndex index)
{
if (index == NodeIndex.Empty) throw new ArgumentException("index cannot be Index.Empty when invoking this method.", nameof(index));
if (ItemReferences == null) throw new InvalidOperationException("The node does not contain enumerable references.");
return ItemReferences[index].TargetNode;
}
/// <inheritdoc/>
public void Update(object? newValue, NodeIndex index)
{
Update(newValue, index, true);
}
/// <inheritdoc/>
public void Add(object newItem)
{
if (Descriptor is CollectionDescriptor collectionDescriptor)
{
NodeIndex index = NodeIndex.Empty;
switch (collectionDescriptor.Category)
{View on GitHub (pinned to 96fad776d2)