{"record":{"id":"dc7eb3d26dc16e04","repo":"stride3d/stride","slug":"while-parsing-a-tag-find-an-incorrect-utf-8-sequence","errorCode":null,"errorMessage":"While parsing a tag, find an incorrect UTF-8 sequence.","messagePattern":"While parsing a tag, find an incorrect UTF-8 sequence\\.","errorType":"exception","errorClass":"SyntaxErrorException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Scanner.cs","lineNumber":2207,"sourceCode":"                    {\n                        throw new SyntaxErrorException(start, mark, \"While parsing a tag, find an incorrect trailing UTF-8 octet.\");\n                    }\n                }\n\n                // Copy the octet and move the pointers.\n\n                charBytes.Add((byte) octet);\n\n                Skip();\n                Skip();\n                Skip();\n            } while (--width > 0);\n\n            char[] characters = Encoding.UTF8.GetChars(charBytes.ToArray());\n\n            if (characters.Length != 1)\n            {\n                throw new SyntaxErrorException(start, mark, \"While parsing a tag, find an incorrect UTF-8 sequence.\");\n            }\n\n            return characters[0];\n        }\n\n        /// <summary>\n        /// Scan a tag handle.\n        /// </summary>\n        private string ScanTagHandle(bool isDirective, Mark start)\n        {\n            // Check the initial '!' character.\n\n            if (!analyzer.Check('!'))\n            {\n                throw new SyntaxErrorException(start, mark, \"While scanning a tag, did not find expected '!'.\");\n            }\n\n            // Copy the '!' character.","sourceCodeStart":2189,"sourceCodeEnd":2225,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Scanner.cs#L2189-L2225","documentation":"After collecting the octets of one URI-escaped character in a tag (Scanner.ScanTagUri), the scanner decodes them with Encoding.UTF8.GetChars. If the bytes do not decode to exactly one char, the escape did not represent a single valid Unicode character, so it throws SyntaxErrorException.","triggerScenarios":"A tag's %XX sequence decodes to zero characters or multiple characters (surrogate pairs or overlong/invalid sequences), e.g. an escape for a UTF-16 surrogate half like '%EDA0%80'.","commonSituations":"Encoding UTF-16 surrogate pairs byte-by-byte instead of the scalar value; overlong UTF-8 encodings; tools that escaped each byte of non-UTF-8 encodings (UTF-16/UTF-32) into tags.","solutions":["Re-encode the tag from a .NET string using UTF-8 percent-encoding (Uri.EscapeDataString) so every escape decodes to one char.","Replace surrogate-half escapes with the proper 4-byte UTF-8 encoding of the code point (e.g. %F0%90%80%80 for U+10000).","Simplify the tag to ASCII characters, which avoids UTF-8 decoding entirely.","Catch SyntaxErrorException and log the mark plus the raw tag text."],"exampleFix":"// before: tag contains bytes of a UTF-16 surrogate half '!%EDA0%BD'\n// after: encode the code point in UTF-8 '!%F0%90%80%BD' or avoid non-ASCII in tags","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { deserializer.Deserialize(reader, targetType); }\ncatch (SyntaxErrorException ex) { throw new YamlConfigException($\"Tag escape does not encode a single valid character at line {ex.Start.Line}\", ex); }","preventionTips":["Never hand-assemble escapes from UTF-16 code units; encode the code point.","Test any tag generator against non-BMP characters (emoji, rare scripts).","Prefer ASCII tags in serializable types."],"tags":["yaml","utf8","encoding"],"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"}