{"record":{"id":"5a8d2332f745fd12","repo":"stride3d/stride","slug":"the-path-tostring-contains-a-non-valid-item-id-on-a","errorCode":null,"errorMessage":"The path [{ToString()}] contains a non-valid item id on a collection.","messagePattern":"The path \\[(.+?)\\] contains a non-valid item id on a collection\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/Yaml/YamlAssetPath.cs","lineNumber":313,"sourceCode":"                            if (key is not int) throw new InvalidOperationException($\"The path [{ToString()}] contains a non-valid item id on an array.\");\n                            int keyInt = (int)key;\n                            memberPath.Push(arrayDescriptor, keyInt);\n                            currentObject = arrayDescriptor.GetValue(currentObject, keyInt);\n                        }\n                        else if (typeDescriptor is CollectionDescriptor collectionDescriptor)\n                        {\n                            if (collectionDescriptor.Category == DescriptorCategory.Set)\n                            {\n                                if (item.Value is null && !collectionDescriptor.ElementType.IsNullable())\n                                {\n                                    throw new InvalidOperationException($\"The path [{ToString()}] contains a null item on a set.\");\n                                }\n                            }\n                            else\n                            {\n                                if (key is not int)\n                                {\n                                    throw new InvalidOperationException($\"The path [{ToString()}] contains a non-valid item id on a collection.\");\n                                }\n                            }\n                            memberPath.Push(collectionDescriptor, key);\n                            currentObject = collectionDescriptor.GetValue(currentObject, key);\n                        }\n                        else if (typeDescriptor is DictionaryDescriptor dictionaryDescriptor)\n                        {\n                            if (key is null) throw new InvalidOperationException($\"The path [{ToString()}] contains a non-valid item id on an dictionary.\");\n                            memberPath.Push(dictionaryDescriptor, key);\n                            currentObject = dictionaryDescriptor.GetValue(currentObject, key);\n                        }\n                        break;\n                    }\n                default:\n                    throw new ArgumentOutOfRangeException();\n            }\n        }\n","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/Yaml/YamlAssetPath.cs#L295-L331","documentation":"Thrown by YamlAssetPath.ToMemberPath when an ItemId path element resolves against a list (non-set collection) but the key derived from the item id is not an integer. Lists are position-based, so only integer keys are valid; a non-int key means the id is stale or was produced for a keyed container.","triggerScenarios":"In the ElementType.ItemId branch, currentObject's descriptor is a CollectionDescriptor with Category != Set and the resolved key is not int (e.g. a Guid or string from a previous set/dictionary representation).","commonSituations":"Container type changed between asset versions (e.g. HashSet<T> changed to List<T> or vice versa), leaving GUID-style ids in paths against lists; duplicated/merged assets; hand-edited YAML.","solutions":["Re-save the asset so list paths are stored as integer indices/item ids matching the current container type","Migrate the container type or the stored path when refactoring a property between list and set/dictionary","Remove and re-create the affected reference in the editor","Catch InvalidOperationException around ToMemberPath and re-link broken references programmatically"],"exampleFix":"// before\nmyList: !AssetRef itemId=\"0a1b-...\"\n// after\nmyList:\n  index: 0","handlingStrategy":"type-guard","validationCode":"var key = ids.GetKey(itemId); if (isList && key is not int) throw new ArgumentException(\"List item ids must resolve to int keys\");","typeGuard":"bool IsIntListItemId(object key) => key is int;","tryCatchPattern":"try { memberPath = yamlPath.ToMemberPath(); } catch (InvalidOperationException) { RebuildPathFromObjectGraph(asset, yamlPath); }","preventionTips":["Migrate stored paths after changing a property between HashSet and List","Re-save assets when container types change so ids match the id map","Avoid hand-editing item-id sections of asset YAML","Run an asset-reference health check after major refactors"],"tags":["yaml","asset-path","collections","item-id"],"backgroundTag":"invalid-identifier-format","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}