stride3d/stride · error · ArgumentException
Anchor value must contain alphanumerical characters only.
Error message
Anchor value must contain alphanumerical characters only.
What it means
Anchor values on nodes may contain only alphanumerical characters (NodeEvent.anchorValidator). NodeEvent's constructor throws System.ArgumentException when a provided anchor fails this regex, e.g. containing dashes, spaces or underscores.
Solutions
- Sanitize the anchor to alphanumerics only before constructing the event
- Generate your own sequential anchor names and reference them consistently
- Handle ArgumentException when constructing node events from untrusted anchor data
- Re-anchor documents from YAML 1.2 sources that use extended anchor characters
Example fix
// before
var anchor = key.Replace(" ", ""); // "my_key" still invalid
// after
var anchor = new string(key.Where(char.IsLetterOrDigit).ToArray());
var evt = new Scalar(anchor.Length > 0 ? anchor : null, tag, value, style, true, false, start, end); Defensive patterns
Strategy: validation
Validate before calling
bool ok = anchor == null || (anchor.Length > 0 && anchor.All(char.IsLetterOrDigit));
if (!ok) throw new ArgumentException($"Anchor '{anchor}' must be non-empty alphanumeric"); Try / catch
try { var evt = new Scalar(anchor, tag, value, style, true, false, start, end); }
catch (ArgumentException ex) when (ex.Message.Contains("alphanumerical")) { /* sanitize the anchor and rebuild */ } Prevention
- Sanitize auto-generated anchors to alphanumerics
- Remember node anchors are validated with ArgumentException, while alias anchors throw YamlException
- Re-anchor YAML 1.2 documents before emitting with this library
When it happens
Trigger: new Scalar("my_node", ...) or any node event with an anchor containing non-alphanumeric characters; deriving anchor names from identifiers such as property names or GUIDs with hyphens.
Common situations: Auto-generating anchors from C# identifiers/keys that contain underscores or dashes; importing YAML 1.2 documents whose anchors legally contain characters YAML 1.1 forbids; user-supplied anchor names.
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
- Anchor value must not be empty.
- 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/dd267076290fa0e4.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/Events/NodeEvent.cs:99
/// 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>
/// Initializes a new instance of the <see cref="NodeEvent"/> class.
/// </summary>
protected NodeEvent(string anchor, string tag)
: this(anchor, tag, Mark.Empty, Mark.Empty)
{View on GitHub (pinned to 96fad776d2)