stride3d/stride · error · YamlException
Anchor value must contain alphanumerical characters only.
Error message
Anchor value must contain alphanumerical characters only.
What it means
Anchor names in YAML may contain only alphanumerical characters (validated by NodeEvent.anchorValidator). The AnchorAlias constructor throws this YamlException when the alias value contains any other character (spaces, punctuation, dashes, etc.).
Solutions
- Strip or transliterate non-alphanumeric characters from the alias before constructing the event
- Generate safe anchors yourself (e.g. anchor1, anchor2) and reference those
- If input YAML uses 1.2-style anchors with dashes, pre-process or re-anchor the nodes
- Catch YamlException around event construction and surface a clear validation message
Example fix
// before
var alias = new AnchorAlias("my-anchor", start, end);
// after
var safe = new string(aliasName.Where(char.IsLetterOrDigit).ToArray());
var alias = new AnchorAlias(safe, start, end); Defensive patterns
Strategy: validation
Validate before calling
bool ok = !string.IsNullOrEmpty(name) && name.All(char.IsLetterOrDigit);
if (!ok) throw new ArgumentException($"Alias '{name}' must be non-empty alphanumeric"); Try / catch
try { var alias = new AnchorAlias(name, start, end); }
catch (YamlException ex) when (ex.Message.Contains("alphanumerical")) { /* sanitize the name and retry */ } Prevention
- Sanitize generated anchor names to [A-Za-z0-9]
- Don't reuse identifiers with dashes/underscores as anchors
- Re-anchor YAML 1.2 inputs before emitting with this library
When it happens
Trigger: new AnchorAlias(value, start, end) where value contains characters outside the anchor grammar, e.g. "my anchor", "a-1", "n&1"; aliases built from user input or identifiers not sanitized to alphanumerics.
Common situations: Using object property names or file names (with dashes/spaces) as anchors; generating anchors from GUIDs or machine names containing hyphens; translating anchors from YAML 1.2 sources that allow a broader anchor charset.
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.
- Unable to find alias
- A serializer factory selector must be sealed before being…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/3add175cbed95f97.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/Events/AnchorAlias.cs:90
public string Value { get { return value; } }
/// <summary>
/// Initializes a new instance of the <see cref="AnchorAlias"/> class.
/// </summary>
/// <param name="value">The value of the alias.</param>
/// <param name="start">The start position of the event.</param>
/// <param name="end">The end position of the event.</param>
public AnchorAlias(string value, Mark start, Mark end)
: base(start, end)
{
if (string.IsNullOrEmpty(value))
{
throw new YamlException(start, end, "Anchor value must not be empty.");
}
if (!NodeEvent.anchorValidator.IsMatch(value))
{
throw new YamlException(start, end, "Anchor value must contain alphanumerical characters only.");
}
this.value = value;
}
/// <summary>
/// Initializes a new instance of the <see cref="AnchorAlias"/> class.
/// </summary>
/// <param name="value">The value of the alias.</param>
public AnchorAlias(string value)
: this(value, Mark.Empty, Mark.Empty)
{
}
/// <summary>
/// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
/// </summary>
/// <returns>View on GitHub (pinned to 96fad776d2)