stride3d/stride · error · ArgumentException
Anchor value must not be empty.
Error message
Anchor value must not be empty.
What it means
NodeEvent is the base class of scalar/sequence/mapping events; when an anchor is supplied it must be non-empty. Unlike the alias variant, this check throws System.ArgumentException (not YamlException) because it is a constructor argument validation on the event object itself.
Solutions
- Pass null instead of "" when a node has no anchor
- Coerce empty strings to null before constructing the event
- Validate anchor names before building node events
- Fix producers that initialize anchor fields to empty strings
Example fix
// before var evt = new Scalar(anchor ?? "", tag, value, style, true, false, start, end); // after var evt = new Scalar(string.IsNullOrEmpty(anchor) ? null : anchor, tag, value, style, true, false, start, end);
Defensive patterns
Strategy: validation
Validate before calling
string safeAnchor = string.IsNullOrEmpty(anchor) ? null : anchor;
if (safeAnchor != null && !safeAnchor.All(char.IsLetterOrDigit)) throw new ArgumentException("Invalid anchor"); Try / catch
try { var evt = new Scalar(anchor, tag, value, style, true, false, start, end); }
catch (ArgumentException ex) when (ex.ParamName == "anchor") { /* coerce to null and rebuild */ } Prevention
- Use null, not string.Empty, for 'no anchor'
- Catch ArgumentException (not YamlException) around node event constructors
- Normalize anchor fields at the source so they are either null or valid
When it happens
Trigger: Passing anchor: "" (not null) to a ScalarEvent/SequenceStartEvent/MappingStartEvent constructor, e.g. new Scalar("", tag, value, ...) — null means 'no anchor', empty string is invalid.
Common situations: Serialization code that defaults anchors with string.Empty instead of null; template interpolation producing ""; converters that emit an anchor attribute for every node even when empty.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Anchor value must contain alphanumerical characters only.
- Anchor value must contain alphanumerical characters only.
- Anchor value must not be empty.
- A serializer factory selector must be sealed before being…
- Aliases are not supported in JSON
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/83814be16622b5d8.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/Events/NodeEvent.cs:94
/// </summary>
/// <value></value>
public abstract bool IsCanonical { get; }
/// <summary>
/// Initializes a new instance of the <see cref="NodeEvent"/> class.
/// </summary>
/// <param name="anchor">The anchor.</param>
/// <param name="tag">The tag.</param>
/// <param name="start">The start position of the event.</param>
/// <param name="end">The end position of the event.</param>
protected NodeEvent(string anchor, string tag, Mark start, Mark end)
: base(start, end)
{
if (anchor != null)
{
if (anchor.Length == 0)
{
throw new ArgumentException("Anchor value must not be empty.", "anchor");
}
if (!anchorValidator.IsMatch(anchor))
{
throw new ArgumentException("Anchor value must contain alphanumerical characters only.", "anchor");
}
}
if (tag != null && tag.Length == 0)
{
throw new ArgumentException("Tag value must not be empty.", "tag");
}
this.anchor = anchor;
this.tag = tag;
}
/// <summary>View on GitHub (pinned to 96fad776d2)