{"record":{"id":"61330c7fb5a3764b","repo":"stride3d/stride","slug":"index-cannot-be-index-empty-when-invoking-this-method","errorCode":null,"errorMessage":"index cannot be Index.Empty when invoking this method.","messagePattern":"index cannot be Index\\.Empty when invoking this method\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Quantum/ObjectNode.cs","lineNumber":75,"sourceCode":"    public event EventHandler<INodeChangeEventArgs>? FinalizeChange;\n\n    /// <inheritdoc/>\n    public event EventHandler<ItemChangeEventArgs>? ItemChanging;\n\n    /// <inheritdoc/>\n    public event EventHandler<ItemChangeEventArgs>? ItemChanged;\n\n    /// <inheritdoc/>\n    public IMemberNode? TryGetChild(string name)\n    {\n        childrenMap.TryGetValue(name, out var child);\n        return child;\n    }\n\n    /// <inheritdoc/>\n    public IObjectNode? IndexedTarget(NodeIndex index)\n    {\n        if (index == NodeIndex.Empty) throw new ArgumentException(\"index cannot be Index.Empty when invoking this method.\", nameof(index));\n        if (ItemReferences == null) throw new InvalidOperationException(\"The node does not contain enumerable references.\");\n        return ItemReferences[index].TargetNode;\n    }\n\n    /// <inheritdoc/>\n    public void Update(object? newValue, NodeIndex index)\n    {\n        Update(newValue, index, true);\n    }\n\n    /// <inheritdoc/>\n    public void Add(object newItem)\n    {\n        if (Descriptor is CollectionDescriptor collectionDescriptor)\n        {\n            NodeIndex index = NodeIndex.Empty;\n            switch (collectionDescriptor.Category)\n            {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Quantum/ObjectNode.cs#L57-L93","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nvar target = node.IndexedTarget(NodeIndex.Empty); // throws\n// after\nif (index != NodeIndex.Empty)\n    var target = node.IndexedTarget(index);","handlingStrategy":"validation","validationCode":"if (index == NodeIndex.Empty) return null; // or throw with context before calling","typeGuard":"static bool HasValidIndex(NodeIndex i) => i != NodeIndex.Empty;","tryCatchPattern":"try { target = node.IndexedTarget(index); }\ncatch (ArgumentException ex) when (ex.ParamName == \"index\")\n{ /* index was NodeIndex.Empty — treat as no target */ }","preventionTips":["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"],"tags":["csharp","quantum","node-graph","argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}