stride3d/stride · error · InvalidOperationException

This instance doesn't contain any path. Use Push() methods…

Error message

This instance doesn't contain any path. Use Push() methods to populate paths

What it means

A MemberPath instance must have at least one path segment, populated via its Push() methods, before Apply() can target anything. Apply() reads items[^1] (the last segment) to decide where the action lands; with an empty path there is nothing to act on, so it throws InvalidOperationException.

Solutions

  1. Populate the path before applying: call Push(MemberDescriptor/PropertyInfo) or Push(CollectionPathItem...) at least once.
  2. Guard with a check like if (path.ItemCount == 0) before calling Apply, and build the path in that branch.
  3. If the path was deserialized, verify the source data actually contained path segments.

Example fix

// before
var path = new MemberPath();
path.Apply(root, MemberPathAction.ValueSet, 42);
// after
var path = new MemberPath();
path.Push(myObjectPropertyDescriptor);
path.Apply(root, MemberPathAction.ValueSet, 42);
Defensive patterns

Strategy: validation

Validate before calling

if (path.ItemCount == 0)
    throw new InvalidOperationException("MemberPath is empty; push at least one segment before Apply.");

Try / catch

try { path.Apply(root, action, value); }
catch (InvalidOperationException ex) when (ex.Message.Contains("doesn't contain any path")) { /* build the path first */ }

Prevention

When it happens

Trigger: Creating a new MemberPath() (or using the default-constructed instance) and immediately calling Apply(root, MemberPathAction.ValueSet, value) without calling Push/ Push Member / Push CollectionItem first.

Common situations: Building paths dynamically where an early return or failed condition skipped all Push calls; deserializing a MemberPath whose items list was empty; unit-test scaffolding that forgot path construction.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at sources/core/Stride.Core.Reflection/MemberPath.cs:231

    {
        if (items.Count > 0)
        {
            items.RemoveAt(items.Count - 1);
        }
    }

    public bool Apply(object rootObject, MemberPathAction actionType, object? value)
    {
        ArgumentNullException.ThrowIfNull(rootObject);
        if (rootObject.GetType().IsValueType) throw new ArgumentException("Value type for root objects are not supported", nameof(rootObject));
        if (actionType != MemberPathAction.ValueSet && actionType != MemberPathAction.CollectionAdd && value != null)
        {
            throw new ArgumentException("Value must be null for action != (MemberActionType.SetValue || MemberPathAction.CollectionAdd)");
        }

        if (items == null || items.Count == 0)
        {
            throw new InvalidOperationException("This instance doesn't contain any path. Use Push() methods to populate paths");
        }

        var lastItem = items[^1];
        switch (actionType)
        {
            case MemberPathAction.CollectionAdd:
                if (lastItem is not CollectionPathItem)
                {
                    throw new ArgumentException("Invalid path [{0}] for action [{1}]. Expecting last path to be a collection item".ToFormat(this, actionType));
                }
                break;
            case MemberPathAction.CollectionRemove:
                if (lastItem is not (CollectionPathItem or ArrayPathItem))
                {
                    throw new ArgumentException("Invalid path [{0}] for action [{1}]. Expecting last path to be a collection/array item".ToFormat(this, actionType));
                }
                break;

View on GitHub (pinned to 96fad776d2)