{"record":{"id":"126fae2d272d0e73","repo":"stride3d/stride","slug":"while-parsing-a-tag-directive-did-not-find-expected","errorCode":null,"errorMessage":"While parsing a tag directive, did not find expected '!'.","messagePattern":"While parsing a tag directive, did not find expected '!'\\.","errorType":"exception","errorClass":"SyntaxErrorException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Scanner.cs","lineNumber":2252,"sourceCode":"                tagHandle.Append(ReadCurrentCharacter());\n            }\n\n            // Check if the trailing character is '!' and copy it.\n\n            if (analyzer.Check('!'))\n            {\n                tagHandle.Append(ReadCurrentCharacter());\n            }\n            else\n            {\n                // It's either the '!' tag or not really a tag handle.  If it's a %TAG\n                // directive, it's an error.  If it's a tag token, it must be a part of\n                // URI.\n\n\n                if (isDirective && (tagHandle.Length != 1 || tagHandle[0] != '!'))\n                {\n                    throw new SyntaxErrorException(start, mark, \"While parsing a tag directive, did not find expected '!'.\");\n                }\n            }\n\n            return tagHandle.ToString();\n        }\n\n        /// <summary>\n        /// Scan the version number of VERSION-DIRECTIVE.\n        ///\n        /// Scope:\n        ///      %YAML   1.1     # a comment \\n\n        ///              ^\n        ///      %YAML   1.1     # a comment \\n\n        ///                ^\n        /// </summary>\n        private int ScanVersionDirectiveNumber(Mark start)\n        {\n            int value = 0;","sourceCodeStart":2234,"sourceCodeEnd":2270,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Scanner.cs#L2234-L2270","documentation":"In Scanner.ScanTagHandle, when scanning a %TAG directive the handle must be exactly one character ('!'), because directive tag handles are only the primary handle '!'. If a directive yields a longer handle not ending in '!' (or otherwise length != 1), the scanner throws SyntaxErrorException.","triggerScenarios":"A %TAG directive whose handle portion is not exactly '!', e.g. '%TAG !foo! ' misspelled without trailing '!' is legal, but '%TAG foo bar' or '%TAG !!' forms that leave a handle of length != 1 in directive mode.","commonSituations":"Hand-written %TAG directives with typos; forgetting that directive handles are only '!' (named handles like '!e!' belong in document tags, not %TAG); editing generated YAML by hand.","solutions":["Make the %TAG handle exactly '!', e.g. '%TAG ! tag:example.com,2000:' or '%TAG !e! tag:example.com,2000:' (handle '!e!' is allowed as it is the named-handle form; the failing case is a malformed handle like 'foo').","If you meant a document-level tag, move it out of the directive line and use '!local!suffix' syntax in the document body.","Run the file through a YAML validator before deserializing.","Catch SyntaxErrorException and report the mark/line of the directive."],"exampleFix":"// before (input.yaml)\n%TAG e tag:example.com,2000:\n\n// after (input.yaml)\n%TAG !e! tag:example.com,2000:","handlingStrategy":"validation","validationCode":"// C#\nforeach (var line in yamlText.Split('\\n').Where(l => l.TrimStart().StartsWith(\"%TAG\")))\n{\n    var handle = line.Trim().Split(' ')[1];\n    if (handle != \"!\" && !(handle.StartsWith(\"!\") && handle.EndsWith(\"!\")))\n        throw new FormatException($\"Bad %TAG handle '{handle}'; use '!' or '!name!'.\");\n}","typeGuard":null,"tryCatchPattern":"try { deserializer.Deserialize(reader, targetType); }\ncatch (SyntaxErrorException ex) { throw new YamlConfigException($\"Invalid %TAG directive handle at line {ex.Start.Line}\", ex); }","preventionTips":["Use the canonical forms: '!' (primary) or '!name!' (named) in %TAG directives.","Never put bare suffixes or URI fragments in the handle slot.","Copy %TAG syntax from the YAML 1.1/1.2 spec examples when hand-writing."],"tags":["yaml","directives","parsing"],"backgroundTag":"yaml-parse-error","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"}