stride3d/stride · error · ArgumentException

The value must be a non-null string when type is ElementType

Error message

The value must be a non-null string when type is ElementType.Member.

What it means

A validation guard in GraphNodePath.PushElement: when the ElementType is Member, the element value must be a non-null string (the member name). PushMember/PushTarget/PushIndex build the node path by pushing typed elements; pushing a Member element with a non-string value (e.g. an index or object) indicates a path-building bug, so an ArgumentOutOfRangeException with this message is thrown instead of corrupting the path.

Solutions

  1. Pass the member name as a string (nameof(Member) or the string constant)
  2. Null-check the name variable before pushing
  3. Use the typed PushMember(string) helper instead of the generic Push(object, ElementType)
  4. Catch ArgumentException at path construction to catch bad inputs early

Example fix

// before
path.Push(null, ElementType.Member);
// after
path.PushMember(nameof(Model.Name));
Defensive patterns

Strategy: type-guard

Validate before calling

if (elementValue is not string name) throw new ArgumentException("Member path element must be a string");

Type guard

bool IsMemberElement(object? v) => v is string s && !string.IsNullOrEmpty(s);

Try / catch

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

Prevention

When it happens

Trigger: Calling PushMember (directly or via Push/PushTarget/PushIndex helpers) with a null or non-string object, e.g. path.Push(null) or passing an enum/int where a member name is expected.

Common situations: Building node paths programmatically with variables of type object; refactorings renaming members so the name variable becomes null; copying path code between Member and Index variants.

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/8b48b66b674e9c82. Report an issue: GitHub.

Appendix: source

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

                    {
                        var objectRefererence = enumerableReference!.Single(x => Equals(x.Index, index));
                        node = objectRefererence.TargetNode;
                    }
                    break;
                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)