stride3d/stride · error · ArgumentException

Cannot create an accessor for an IMemberNode that use a…

Error message

Cannot create an accessor for an IMemberNode that use a non-empty index.

What it means

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.

Solutions

  1. Pass NodeIndex.Empty when the node is an IMemberNode.
  2. Check node is IMemberNode before constructing and strip/reset the index, or route member nodes to a dedicated code path.
  3. 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.

Example fix

// before
var accessor = new NodeAccessor(memberNode, NodeIndex.New(0));
// after
var accessor = new NodeAccessor(memberNode, memberNode is IMemberNode ? NodeIndex.Empty : index);
Defensive patterns

Strategy: validation

Validate before calling

// C#
var effectiveIndex = node is IMemberNode ? NodeIndex.Empty : index;
var accessor = new NodeAccessor(node, effectiveIndex);

Type guard

static bool ValidAccessorArgs(IGraphNode node, NodeIndex index) => node is not IMemberNode || index.IsEmpty;

Try / catch

try { var accessor = new NodeAccessor(node, index); }
catch (ArgumentException ex) when (ex.Message.Contains("non-empty index")) { var accessor = new NodeAccessor(node, NodeIndex.Empty); }

Prevention

When it happens

Trigger: new NodeAccessor(memberNode, NodeIndex.New(keyOrInt)) — i.e. constructing an accessor with a node that implements IMemberNode while the index is not NodeIndex.Empty.

Common situations: 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.

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


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/af678b734a25944f. Report an issue: GitHub.

Appendix: source

Thrown at sources/presentation/Stride.Core.Quantum/NodeAccessor.cs:30

{
    /// <summary>
    /// The node of the accessor.
    /// </summary>
    public readonly IGraphNode Node;
    /// <summary>
    /// The index of the accessor.
    /// </summary>
    public readonly NodeIndex Index;

    /// <summary>
    /// Initializes a new instance of the <see cref="NodeAccessor"/> structure.
    /// </summary>
    /// <param name="node">The target node of this accessor.</param>
    /// <param name="index">The index of the target item if this accessor target an item. <see cref="NodeIndex.Empty"/> otherwise.</param>
    public NodeAccessor(IGraphNode node, NodeIndex index)
    {
        ArgumentNullException.ThrowIfNull(node);
        if (node is IMemberNode && !index.IsEmpty) throw new ArgumentException($"Cannot create an accessor for an {nameof(IMemberNode)} that use a non-empty index.");
        Node = node;
        Index = index;
    }

    /// <summary>
    /// Gets whether this accessor is targeting a member of an object.
    /// </summary>
    public readonly bool IsMember => Node is IMemberNode;

    /// <summary>
    /// Gets whether this accessor is targeting an item of a collection.
    /// </summary>
    public readonly bool IsItem => Node is IObjectNode && !Index.IsEmpty;

    /// <summary>
    /// Retrieves the value backed by this accessor.
    /// </summary>
    /// <returns>The value backed by this accessor.</returns>

View on GitHub (pinned to 96fad776d2)