stride3d/stride · error · InvalidOperationException
This item is not a item Id
Error message
This item is not a item Id
What it means
YamlAssetPath.Element.AsItemId() casts the element's Value to ItemId and throws InvalidOperationException('This item is not a item Id') when the element's Type is not ElementType.ItemId (e.g. it is a Member or Index).
Solutions
- Check element.Type == ElementType.ItemId before calling AsItemId()
- Dispatch on ElementType instead of assuming the kind
- Fix the path construction site to push ItemId elements where expected
- Skip non-ItemId elements in loops that collect ids
Example fix
// before var id = element.AsItemId(); // after var id = element.Type == YamlAssetPath.ElementType.ItemId ? element.AsItemId() : (ItemId?)null;
Defensive patterns
Strategy: type-guard
Validate before calling
if (element.Type != YamlAssetPath.ElementType.ItemId) return; // not an id element
Type guard
bool TryAsItemId(in YamlAssetPath.Element e, out ItemId id)
{ id = e.Type == YamlAssetPath.ElementType.ItemId ? e.AsItemId() : default; return e.Type == YamlAssetPath.ElementType.ItemId; } Try / catch
try { id = element.AsItemId(); }
catch (InvalidOperationException ex) { logger.Error(ex, "Path element is not an ItemId"); } Prevention
- Check ElementType before extracting values
- Only expect ItemIds on collection elements
- Cover member and item paths in unit tests
When it happens
Trigger: Calling AsItemId() on a Member or Index element — e.g. extracting object ids from remapping paths where only some elements carry item ids.
Common situations: Asset-upgrade/dependency-fixup code scanning paths for ItemIds; scripts that assume every path element has an id; paths built for plain members (no collection) then processed with item-id logic.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- This item is not a Member
- Unable to extract url reference from object
- The given container does not match the expected type.
- The given container does not match the expected type.
- The path [ ] contains access to a member of a null object.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/092b10fd7bc42104.
Report an issue: GitHub.
Appendix: source
Thrown at sources/assets/Stride.Core.Assets/Yaml/YamlAssetPath.cs:78
}
/// <summary>
/// Fetches the name of the member, considering this element is a <see cref="ElementType.Member"/>.
/// </summary>
/// <returns>The name of the member.</returns>
public readonly string AsMember()
{
if (Type != ElementType.Member) throw new InvalidOperationException("This item is not a Member");
return (string)Value;
}
/// <summary>
/// Returns the <see cref="ItemId"/> of this element, considering this element is a <see cref="ElementType.ItemId"/>.
/// </summary>
/// <returns>The <see cref="ItemId"/> of the item.</returns>
public readonly ItemId AsItemId()
{
if (Type != ElementType.ItemId) throw new InvalidOperationException("This item is not a item Id");
return (ItemId)Value;
}
/// <inheritdoc/>
public readonly bool Equals(Element other)
{
return Type == other.Type && Equals(Value, other.Value);
}
/// <inheritdoc/>
public override readonly bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
return obj is Element element && Equals(element);
}
/// <inheritdoc/>
public override readonly int GetHashCode()View on GitHub (pinned to 96fad776d2)