{"record":{"id":"6f6ac91e1019dfab","repo":"stride3d/stride","slug":"invalid-path-0-for-action-1-expecting-last-path-to-be-a-6f6ac9","errorCode":null,"errorMessage":"Invalid path [{0}] for action [{1}]. Expecting last path to be a collection/array item","messagePattern":"Invalid path \\[(.+?)\\] for action \\[(.+?)\\]\\. Expecting last path to be a collection/array item","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Reflection/MemberPath.cs","lineNumber":246,"sourceCode":"\n        if (items == null || items.Count == 0)\n        {\n            throw new InvalidOperationException(\"This instance doesn't contain any path. Use Push() methods to populate paths\");\n        }\n\n        var lastItem = items[^1];\n        switch (actionType)\n        {\n            case MemberPathAction.CollectionAdd:\n                if (lastItem is not CollectionPathItem)\n                {\n                    throw new ArgumentException(\"Invalid path [{0}] for action [{1}]. Expecting last path to be a collection item\".ToFormat(this, actionType));\n                }\n                break;\n            case MemberPathAction.CollectionRemove:\n                if (lastItem is not (CollectionPathItem or ArrayPathItem))\n                {\n                    throw new ArgumentException(\"Invalid path [{0}] for action [{1}]. Expecting last path to be a collection/array item\".ToFormat(this, actionType));\n                }\n                break;\n\n            case MemberPathAction.DictionaryRemove:\n                if (lastItem is not DictionaryPathItem)\n                {\n                    throw new ArgumentException(\"Invalid path [{0}] for action [{1}]. Expecting last path to be a dictionary item\".ToFormat(this, actionType));\n                }\n                break;\n        }\n\n        var stack = stackTLS;\n        try\n        {\n            object? nextObject = rootObject;\n\n            if (stack == null)\n            {","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Reflection/MemberPath.cs#L228-L264","documentation":"MemberPathAction.CollectionRemove requires the last path segment to point at the element being removed, i.e. it must be a CollectionPathItem or ArrayPathItem. Apply() throws ArgumentException when the path terminates on any other kind of segment (member or dictionary item).","triggerScenarios":"Calling Apply(root, MemberPathAction.CollectionRemove, null) on a path whose final segment is a MemberPathItem, DictionaryPathItem, or the empty/member path rather than a collection/array element.","commonSituations":"Building a path with Push(member) only and trying to remove from the collection property; confusing dictionary removal (DictionaryRemove) with list removal and reusing a dictionary-shaped path.","solutions":["Push the collection or array element segment (PushCollectionItem / PushArrayItem) as the final segment so it identifies the exact element to remove.","For dictionaries, switch to MemberPathAction.DictionaryRemove instead.","Inspect the path's last item type before calling Apply and branch on it."],"exampleFix":"// before\nvar path = new MemberPath();\npath.Push(type.GetProperty(\"Items\"));\npath.Apply(root, MemberPathAction.CollectionRemove, null);\n// after\nvar path = new MemberPath();\npath.Push(type.GetProperty(\"Items\"));\npath.PushCollectionItem(indexToRemove);\npath.Apply(root, MemberPathAction.CollectionRemove, null);","handlingStrategy":"validation","validationCode":"var last = path.Items[^1];\nif (action == MemberPathAction.CollectionRemove && last is not (CollectionPathItem or ArrayPathItem))\n    throw new InvalidOperationException(\"CollectionRemove requires a collection/array-item path segment.\");","typeGuard":"static bool CanCollectionRemove(MemberPath p) => p.Items.Count > 0 && p.Items[^1] is CollectionPathItem or ArrayPathItem;","tryCatchPattern":"try { path.Apply(root, MemberPathAction.CollectionRemove, null); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Expecting last path to be a collection/array item\")) { /* reshape the path */ }","preventionTips":["Identify the exact element to remove with a collection/array item segment before calling CollectionRemove.","Dispatch on the last segment's type when writing generic path-editing utilities."],"tags":["path-shape","reflection","collections"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}