{"record":{"id":"dd267076290fa0e4","repo":"stride3d/stride","slug":"anchor-value-must-contain-alphanumerical-characters-only-dd2670","errorCode":null,"errorMessage":"Anchor value must contain alphanumerical characters only.","messagePattern":"Anchor value must contain alphanumerical characters only\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Events/NodeEvent.cs","lineNumber":99,"sourceCode":"        /// Initializes a new instance of the <see cref=\"NodeEvent\"/> class.\n        /// </summary>\n        /// <param name=\"anchor\">The anchor.</param>\n        /// <param name=\"tag\">The tag.</param>\n        /// <param name=\"start\">The start position of the event.</param>\n        /// <param name=\"end\">The end position of the event.</param>\n        protected NodeEvent(string anchor, string tag, Mark start, Mark end)\n            : base(start, end)\n        {\n            if (anchor != null)\n            {\n                if (anchor.Length == 0)\n                {\n                    throw new ArgumentException(\"Anchor value must not be empty.\", \"anchor\");\n                }\n\n                if (!anchorValidator.IsMatch(anchor))\n                {\n                    throw new ArgumentException(\"Anchor value must contain alphanumerical characters only.\", \"anchor\");\n                }\n            }\n\n            if (tag != null && tag.Length == 0)\n            {\n                throw new ArgumentException(\"Tag value must not be empty.\", \"tag\");\n            }\n\n            this.anchor = anchor;\n            this.tag = tag;\n        }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"NodeEvent\"/> class.\n        /// </summary>\n        protected NodeEvent(string anchor, string tag)\n            : this(anchor, tag, Mark.Empty, Mark.Empty)\n        {","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Events/NodeEvent.cs#L81-L117","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nvar anchor = key.Replace(\" \", \"\"); // \"my_key\" still invalid\n// after\nvar anchor = new string(key.Where(char.IsLetterOrDigit).ToArray());\nvar evt = new Scalar(anchor.Length > 0 ? anchor : null, tag, value, style, true, false, start, end);","handlingStrategy":"validation","validationCode":"bool ok = anchor == null || (anchor.Length > 0 && anchor.All(char.IsLetterOrDigit));\nif (!ok) throw new ArgumentException($\"Anchor '{anchor}' must be non-empty alphanumeric\");","typeGuard":null,"tryCatchPattern":"try { var evt = new Scalar(anchor, tag, value, style, true, false, start, end); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"alphanumerical\")) { /* sanitize the anchor and rebuild */ }","preventionTips":["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"],"tags":["yaml","anchor","argument-exception"],"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"}