stride3d/stride · error · InvalidOperationException
This item is not a Member
Error message
This item is not a Member
What it means
YamlAssetPath.Element is a tagged union: its Value meaning depends on Type (Member name string, Index int, ItemId Guid). AsMember() casts Value to string and throws InvalidOperationException if the element's Type is not ElementType.Member.
Solutions
- Check item.Type == ElementType.Member before calling AsMember()
- Use switch/if on ElementType to dispatch to AsMember/AsItemId/Index appropriately
- Fix the code that built the YamlAssetPath so member elements are pushed with PushMember
- Log the element Type to find where the wrong element was appended
Example fix
// before
string name = element.AsMember();
// after
string name = element.Type == YamlAssetPath.ElementType.Member
? element.AsMember()
: throw new InvalidOperationException($"Unexpected element type {element.Type}"); Defensive patterns
Strategy: type-guard
Validate before calling
if (element.Type != YamlAssetPath.ElementType.Member)
throw new InvalidOperationException($"Element is {element.Type}, expected Member"); Type guard
bool TryAsMember(in YamlAssetPath.Element e, out string name)
{ name = e.Type == YamlAssetPath.ElementType.Member ? e.AsMember() : null; return name is not null; } Try / catch
try { name = element.AsMember(); }
catch (InvalidOperationException ex) { logger.Error(ex, "Path element is not a member"); continue; } Prevention
- Dispatch on ElementType before reading values
- Push member elements only via PushMember
- Test path round-trips for lists/dictionaries, not just members
When it happens
Trigger: Calling AsMember() on a path element whose ElementType is Index or ItemId — e.g. iterating path elements and assuming all are members when a path also contains collection indices or item ids.
Common situations: Editor/plugin code walking YamlAssetPath elements to build UI breadcrumbs or fixups; scripts mis-parsing paths produced for list items or dictionary entries; off-by-one in path construction so a member call lands on an index element.
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 item Id
- 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/6e1031459dfa4265.
Report an issue: GitHub.
Appendix: source
Thrown at sources/assets/Stride.Core.Assets/Yaml/YamlAssetPath.cs:68
/// <summary>
/// Initializes a new instance of the <see cref="Element"/> structure.
/// </summary>
/// <param name="type">The type of element.</param>
/// <param name="value">The value of the element.</param>
public Element(ElementType type, object value)
{
Type = type;
Value = value;
}
/// <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);
}View on GitHub (pinned to 96fad776d2)