stride3d/stride · error · ArgumentException

The value must be null when type is ElementType.Target.

Error message

The value must be null when type is ElementType.Target.

What it means

GraphNodePath.PushElement throws ArgumentException when ElementType.Target is requested but the element value is not null. A Target path segment carries no payload; it is a marker, so any non-null value is invalid input.

Solutions

  1. Pass null explicitly when pushing an ElementType.Target segment
  2. Use the parameterless PushTarget() helper instead of the generic Push
  3. Add an assertion that value is null before calling Push with Target
  4. Catch ArgumentException during path construction

Example fix

// before
path.Push(targetObj, ElementType.Target);
// after
path.PushTarget();
Defensive patterns

Strategy: type-guard

Validate before calling

if (elementValue != null) throw new ArgumentException("Target path element must be null");

Type guard

bool IsValidTargetElement(object? v) => v is null;

Try / catch

try { path.Push(value, ElementType.Target); } catch (ArgumentException ex) { logger.LogError(ex, "Invalid target path element"); }

Prevention

When it happens

Trigger: Calling PushTarget via the generic Push API with a non-null object (e.g. path.Push(someValue, ElementType.Target)) instead of null.

Common situations: Generic path-building code that forwards the same value to Member/Target/Index cases; ported code from other path APIs where Target carries a value.

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/88356a1803ee2f76. Report an issue: GitHub.

Appendix: source

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

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
        return memberPath;
    }

    private void PushElement(object? elementValue, ElementType type)
    {
        switch (type)
        {
            case ElementType.Member:
                if (elementValue is not string name)
                    throw new ArgumentException("The value must be a non-null string when type is ElementType.Member.");
                path.Add(NodePathElement.CreateMember(name));
                break;
            case ElementType.Target:
                if (elementValue != null)
                    throw new ArgumentException("The value must be null when type is ElementType.Target.");
                path.Add(NodePathElement.CreateTarget());
                break;
            case ElementType.Index:
                if (!(elementValue is NodeIndex))
                    throw new ArgumentException("The value must be an Index when type is ElementType.Index.");
                path.Add(NodePathElement.CreateIndex((NodeIndex)elementValue));
                break;
            default:
                throw new ArgumentOutOfRangeException(nameof(type));
        }
    }
}

View on GitHub (pinned to 96fad776d2)