{"record":{"id":"3add175cbed95f97","repo":"stride3d/stride","slug":"anchor-value-must-contain-alphanumerical-characters-only","errorCode":null,"errorMessage":"Anchor value must contain alphanumerical characters only.","messagePattern":"Anchor value must contain alphanumerical characters only\\.","errorType":"exception","errorClass":"YamlException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Events/AnchorAlias.cs","lineNumber":90,"sourceCode":"        public string Value { get { return value; } }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"AnchorAlias\"/> class.\n        /// </summary>\n        /// <param name=\"value\">The value of the alias.</param>\n        /// <param name=\"start\">The start position of the event.</param>\n        /// <param name=\"end\">The end position of the event.</param>\n        public AnchorAlias(string value, Mark start, Mark end)\n            : base(start, end)\n        {\n            if (string.IsNullOrEmpty(value))\n            {\n                throw new YamlException(start, end, \"Anchor value must not be empty.\");\n            }\n\n            if (!NodeEvent.anchorValidator.IsMatch(value))\n            {\n                throw new YamlException(start, end, \"Anchor value must contain alphanumerical characters only.\");\n            }\n\n            this.value = value;\n        }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"AnchorAlias\"/> class.\n        /// </summary>\n        /// <param name=\"value\">The value of the alias.</param>\n        public AnchorAlias(string value)\n            : this(value, Mark.Empty, Mark.Empty)\n        {\n        }\n\n        /// <summary>\n        /// Returns a <see cref=\"T:System.String\"/> that represents the current <see cref=\"T:System.Object\"/>.\n        /// </summary>\n        /// <returns>","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Events/AnchorAlias.cs#L72-L108","documentation":"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.).","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nvar alias = new AnchorAlias(\"my-anchor\", start, end);\n// after\nvar safe = new string(aliasName.Where(char.IsLetterOrDigit).ToArray());\nvar alias = new AnchorAlias(safe, start, end);","handlingStrategy":"validation","validationCode":"bool ok = !string.IsNullOrEmpty(name) && name.All(char.IsLetterOrDigit);\nif (!ok) throw new ArgumentException($\"Alias '{name}' must be non-empty alphanumeric\");","typeGuard":null,"tryCatchPattern":"try { var alias = new AnchorAlias(name, start, end); }\ncatch (YamlException ex) when (ex.Message.Contains(\"alphanumerical\")) { /* sanitize the name and retry */ }","preventionTips":["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"],"tags":["yaml","anchor","alias"],"backgroundTag":"invalid-identifier-format","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}