{"record":{"id":"5615c9612851a4a3","repo":"stride3d/stride","slug":"invalid-path-0-for-action-1-expecting-last-path-to-be-a-5615c9","errorCode":null,"errorMessage":"Invalid path [{0}] for action [{1}]. Expecting last path to be a dictionary item","messagePattern":"Invalid path \\[(.+?)\\] for action \\[(.+?)\\]\\. Expecting last path to be a dictionary item","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Reflection/MemberPath.cs","lineNumber":253,"sourceCode":"        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            {\n                stack = [];\n                stackTLS = stack;\n            }\n            else\n            {\n                stack.Clear();\n            }","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Reflection/MemberPath.cs#L235-L271","documentation":"MemberPathAction.DictionaryRemove requires the last path segment to be a DictionaryPathItem identifying the key to remove. Apply() throws ArgumentException when the final segment is a member, collection item, or array item.","triggerScenarios":"Calling Apply(root, MemberPathAction.DictionaryRemove, null) on a path that ends with a MemberPathItem (e.g. just the dictionary property) or a CollectionPathItem/ArrayPathItem.","commonSituations":"Reusing a list-shaped path and switching the action to DictionaryRemove; forgetting to push the dictionary-key segment (PushDictionaryItem) after pushing the dictionary member.","solutions":["Push a dictionary key segment (PushDictionaryItem) as the final path segment before calling DictionaryRemove.","For lists/arrays, use MemberPathAction.CollectionRemove instead.","Validate lastItem is DictionaryPathItem before invoking Apply in generic helper code."],"exampleFix":"// before\nvar path = new MemberPath();\npath.Push(type.GetProperty(\"Settings\"));\npath.Apply(root, MemberPathAction.DictionaryRemove, null);\n// after\nvar path = new MemberPath();\npath.Push(type.GetProperty(\"Settings\"));\npath.PushDictionaryItem(\"someKey\");\npath.Apply(root, MemberPathAction.DictionaryRemove, null);","handlingStrategy":"validation","validationCode":"var last = path.Items[^1];\nif (action == MemberPathAction.DictionaryRemove && last is not DictionaryPathItem)\n    throw new InvalidOperationException(\"DictionaryRemove requires a dictionary-item path segment.\");","typeGuard":"static bool CanDictionaryRemove(MemberPath p) => p.Items.Count > 0 && p.Items[^1] is DictionaryPathItem;","tryCatchPattern":"try { path.Apply(root, MemberPathAction.DictionaryRemove, null); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Expecting last path to be a dictionary item\")) { /* push a dictionary-key segment */ }","preventionTips":["Push the key segment (PushDictionaryItem) as the final segment for dictionary removals.","Keep separate builder helpers for list-shaped vs dictionary-shaped paths."],"tags":["path-shape","reflection","dictionary"],"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"}