{"record":{"id":"af678b734a25944f","repo":"stride3d/stride","slug":"cannot-create-an-accessor-for-an-imembernode-that-use-a-non","errorCode":null,"errorMessage":"Cannot create an accessor for an IMemberNode that use a non-empty index.","messagePattern":"Cannot create an accessor for an IMemberNode that use a non-empty index\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Quantum/NodeAccessor.cs","lineNumber":30,"sourceCode":"{\n    /// <summary>\n    /// The node of the accessor.\n    /// </summary>\n    public readonly IGraphNode Node;\n    /// <summary>\n    /// The index of the accessor.\n    /// </summary>\n    public readonly NodeIndex Index;\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"NodeAccessor\"/> structure.\n    /// </summary>\n    /// <param name=\"node\">The target node of this accessor.</param>\n    /// <param name=\"index\">The index of the target item if this accessor target an item. <see cref=\"NodeIndex.Empty\"/> otherwise.</param>\n    public NodeAccessor(IGraphNode node, NodeIndex index)\n    {\n        ArgumentNullException.ThrowIfNull(node);\n        if (node is IMemberNode && !index.IsEmpty) throw new ArgumentException($\"Cannot create an accessor for an {nameof(IMemberNode)} that use a non-empty index.\");\n        Node = node;\n        Index = index;\n    }\n\n    /// <summary>\n    /// Gets whether this accessor is targeting a member of an object.\n    /// </summary>\n    public readonly bool IsMember => Node is IMemberNode;\n\n    /// <summary>\n    /// Gets whether this accessor is targeting an item of a collection.\n    /// </summary>\n    public readonly bool IsItem => Node is IObjectNode && !Index.IsEmpty;\n\n    /// <summary>\n    /// Retrieves the value backed by this accessor.\n    /// </summary>\n    /// <returns>The value backed by this accessor.</returns>","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Quantum/NodeAccessor.cs#L12-L48","documentation":"NodeAccessor pairs a graph node with the index of the item it targets. Member nodes are properties, not collections, so they can only be targeted with NodeIndex.Empty; an accessor for an IMemberNode with a non-empty index is meaningless. The constructor throws ArgumentException to reject this misuse up front.","triggerScenarios":"new NodeAccessor(memberNode, NodeIndex.New(keyOrInt)) — i.e. constructing an accessor with a node that implements IMemberNode while the index is not NodeIndex.Empty.","commonSituations":"Generic accessor-creation code that carries an index from an item-node lookup and reuses it for a member node; code that treats all IGraphNode instances uniformly without checking for IMemberNode.","solutions":["Pass NodeIndex.Empty when the node is an IMemberNode.","Check node is IMemberNode before constructing and strip/reset the index, or route member nodes to a dedicated code path.","If indexing is actually needed, the target should be an item node (e.g. obtained via memberNode.ItemReferences / an indexed node), not the member node itself."],"exampleFix":"// before\nvar accessor = new NodeAccessor(memberNode, NodeIndex.New(0));\n// after\nvar accessor = new NodeAccessor(memberNode, memberNode is IMemberNode ? NodeIndex.Empty : index);","handlingStrategy":"validation","validationCode":"// C#\nvar effectiveIndex = node is IMemberNode ? NodeIndex.Empty : index;\nvar accessor = new NodeAccessor(node, effectiveIndex);","typeGuard":"static bool ValidAccessorArgs(IGraphNode node, NodeIndex index) => node is not IMemberNode || index.IsEmpty;","tryCatchPattern":"try { var accessor = new NodeAccessor(node, index); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"non-empty index\")) { var accessor = new NodeAccessor(node, NodeIndex.Empty); }","preventionTips":["Check node is IMemberNode before constructing accessors and reset the index","Remember only item (indexed) nodes accept non-empty NodeIndex","Centralize accessor construction in one helper that normalizes the index","Do not blindly propagate indices from lookups into accessor construction"],"tags":["argument-validation","graph-node","index","stride-quantum"],"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"}