stride3d/stride · error · InvalidOperationException
The path [ ] contains a non-valid item id on an array.
Error message
The path [{ToString()}] contains a non-valid item id on an array. What it means
Thrown by YamlAssetPath.ToMemberPath when resolving an ItemId-style path element against an array but the id's key is not an integer. Arrays support only positional (int) item ids, so any other key type (string, Guid, etc.) means the stored id is corrupt or was written for a different container kind.
Solutions
- Fix the asset YAML so array elements are addressed by integer index rather than a GUID item id
- Regenerate the reference in the editor so a correct positional path is stored
- If the property changed container type, migrate the asset to the new addressing scheme
- Catch InvalidOperationException around ToMemberPath and fall back to re-linking the reference
Example fix
// before (asset yaml) array: !AssetRef itemId="d0e1..." // after array: index: 2
Defensive patterns
Strategy: type-guard
Validate before calling
var key = ids.GetKey(itemId); if (key is not int) throw new ArgumentException("Array item ids must resolve to int keys"); Type guard
bool IsIntArrayItemId(object key) => key is int;
Try / catch
try { memberPath = yamlPath.ToMemberPath(); } catch (InvalidOperationException) { RelinkReference(asset, yamlPath); } Prevention
- Address array elements positionally (int index), never with GUID item ids
- Migrate stored paths when a property changes container type (list/set -> array)
- Re-save affected assets after serializer version upgrades
- Automatically re-link references whose paths fail to resolve
When it happens
Trigger: In the ElementType.ItemId branch, CollectionItemIdHelper.GetCollectionItemIds(currentObject).GetKey(item.AsItemId()) returns a non-int key while the current object's descriptor is an ArrayDescriptor.
Common situations: Asset YAML where an array element was addressed with a GUID-style identifier (e.g. after the property was converted from a list/set to an array); corrupted or hand-edited asset files; serializer version differences in how item ids are emitted.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- The path [ ] contains non-integer index on an array.
- The path [ ] contains a non-valid item id on a collection.
- The path [ ] contains a non-valid item id on an dictionary.
- The path [ ] contains a null item on a set.
- The path [ ] item doesn't exsit on a set.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/c4a7ba9bcad724f5.
Report an issue: GitHub.
Appendix: source
Thrown at sources/assets/Stride.Core.Assets/Yaml/YamlAssetPath.cs:295
currentObject = collectionDescriptor.GetValue(currentObject, item.Value);
}
}
else if (typeDescriptor is DictionaryDescriptor dictionaryDescriptor)
{
if (item.Value is null) throw new InvalidOperationException($"The path [{ToString()}] contains a null key on an dictionary.");
memberPath.Push(dictionaryDescriptor, item.Value);
currentObject = dictionaryDescriptor.GetValue(currentObject, item.Value);
}
break;
}
case ElementType.ItemId:
{
var ids = CollectionItemIdHelper.GetCollectionItemIds(currentObject);
var key = ids.GetKey(item.AsItemId());
var typeDescriptor = TypeDescriptorFactory.Default.Find(currentObject.GetType());
if (typeDescriptor is ArrayDescriptor arrayDescriptor)
{
if (key is not int) throw new InvalidOperationException($"The path [{ToString()}] contains a non-valid item id on an array.");
int keyInt = (int)key;
memberPath.Push(arrayDescriptor, keyInt);
currentObject = arrayDescriptor.GetValue(currentObject, keyInt);
}
else if (typeDescriptor is CollectionDescriptor collectionDescriptor)
{
if (collectionDescriptor.Category == DescriptorCategory.Set)
{
if (item.Value is null && !collectionDescriptor.ElementType.IsNullable())
{
throw new InvalidOperationException($"The path [{ToString()}] contains a null item on a set.");
}
}
else
{
if (key is not int)
{
throw new InvalidOperationException($"The path [{ToString()}] contains a non-valid item id on a collection.");View on GitHub (pinned to 96fad776d2)