stride3d/stride · error · InvalidOperationException

A node of the path is null but is not the last node.

Error message

A node of the path is null but is not the last node.

What it means

GraphNodePath's enumerator (MoveNext) throws InvalidOperationException when a node in the middle of the path resolves to null while more path elements remain. A null intermediate node means the remaining path segments cannot be resolved, so continuing would be meaningless.

Solutions

  1. Re-resolve/rebuild the node path after model changes instead of reusing the stale one
  2. Check node existence (e.g. NodeContainer.TryGetNode) before walking the remaining path
  3. Avoid mutating the graph while enumerating paths; snapshot first
  4. Catch InvalidOperationException during iteration and treat the path as invalid

Example fix

// before
foreach (var node in stalePath) { ... }
// after
if (NodeContainer.TryGetNode(path, out var node)) { /* use node */ }
Defensive patterns

Strategy: validation

Validate before calling

if (!NodeContainer.TryGetNode(path, out var node)) throw new InvalidOperationException("Path no longer resolves; rebuild it");

Try / catch

try { foreach (var n in graphNodePath) { ... } } catch (InvalidOperationException ex) when (ex.Message.Contains("path is null")) { rebuildPath(); }

Prevention

When it happens

Trigger: Enumerating a GraphNodePath whose chained nodes (member/index/target lookups) produced null for a non-final node — e.g. a member node was removed from its parent while a path referencing it was still being walked.

Common situations: Holding stale node paths after the model changed (member deleted, list cleared); iterating paths concurrently with graph mutation; resolving paths against partially built containers.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at sources/presentation/Stride.Core.Quantum/GraphNodePath.cs:172

            {
                current = path.RootNode;
            }
            else
            {
                var element = path.path[index];
                current = element.Type switch
                {
                    ElementType.Member => ((IObjectNode)Current)[element.Name!],
                    ElementType.Target => ((IMemberNode)Current).Target,
                    ElementType.Index => ((IObjectNode)Current).ItemReferences?[element.Index].TargetNode,
                    _ => throw new ArgumentOutOfRangeException(),
                };
            }
            ++index;

            // If a node that is not the last one is null, we cannot process the path.
            if (current is null && index < path.path.Count)
                throw new InvalidOperationException("A node of the path is null but is not the last node.");

            return true;
        }

        public void Reset()
        {
            index = -1;
        }

        public readonly IGraphNode Current => current!;

        readonly object IEnumerator.Current => current!;
    }

    private const int DefaultCapacity = 16;
    private readonly List<NodePathElement> path;

    private GraphNodePath(IGraphNode rootNode, int defaultCapacity)

View on GitHub (pinned to 96fad776d2)