stride3d/stride · error · AnchorNotFoundException

The anchor ' ' does not exists

Error message

The anchor '{0}' does not exists

What it means

DocumentLoadingState.GetNode resolves an alias like *anchor to the node previously registered under that anchor; when the anchor is not found and throwException is true it throws AnchorNotFoundException. This means the document contains an alias referencing an anchor that was never defined (or not yet defined at that point).

Solutions

  1. Add the missing &anchor declaration before the alias use in the document
  2. Fix the alias name typo so it matches an existing anchor
  3. Reorder so the anchored node precedes its alias (YAML requires forward definitions only within a document)
  4. If optional, call the lookup path with throwException=false and handle the null return

Example fix

// before
settings: *shared
// after
shared: &shared {retries: 3}
settings: *shared
Defensive patterns

Strategy: validation

Validate before calling

var anchors = Regex.Matches(yaml, "&([A-Za-z0-9_-]+)").Select(m => m.Groups[1].Value).ToHashSet();
var aliases = Regex.Matches(yaml, "\*([A-Za-z0-9_-]+)").Select(m => m.Groups[1].Value);
var missing = aliases.Where(a => !anchors.Contains(a)).ToList();
if (missing.Count > 0) throw new InvalidDataException($"Aliases without anchors: {string.Join(",", missing)}");

Try / catch

try { return serializer.Deserialize(stream, typeof(Config)); }
catch (AnchorNotFoundException ex) { throw new InvalidDataException($"Alias '{ex.Anchor}' has no matching anchor", ex); }

Prevention

When it happens

Trigger: YAML contains *alias but the corresponding &anchor was never declared; the alias appears before its anchor in document order; a typo in the alias name; the anchor was defined in a different document/stream than the alias.

Common situations: Hand-written YAML referencing anchors from an included or merged file; renaming an anchor without updating aliases; copy-pasting alias nodes into documents that lack their anchors.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/ce1fba60a69c0199. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.Yaml/Serialization/DocumentLoadingState.cs:96

        /// <summary>
        /// Gets the node with the specified anchor.
        /// </summary>
        /// <param name="anchor">The anchor.</param>
        /// <param name="throwException">if set to <c>true</c>, the method should throw an exception if there is no node with that anchor.</param>
        /// <param name="start">The start position.</param>
        /// <param name="end">The end position.</param>
        /// <returns></returns>
        public YamlNode GetNode(string anchor, bool throwException, Mark start, Mark end)
        {
            YamlNode target;
            if (anchors.TryGetValue(anchor, out target))
            {
                return target;
            }
            else if (throwException)
            {
                throw new AnchorNotFoundException(anchor, start, end, string.Format(CultureInfo.InvariantCulture, "The anchor '{0}' does not exists", anchor));
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// Adds the specified node to the collection of nodes with unresolved aliases.
        /// </summary>
        /// <param name="node">
        /// The <see cref="YamlNode"/> that has unresolved aliases.
        /// </param>
        public void AddNodeWithUnresolvedAliases(YamlNode node)
        {
            nodesWithUnresolvedAliases.Add(node);
        }

View on GitHub (pinned to 96fad776d2)