stride3d/stride · error · SyntaxErrorException

While parsing a quoted scalar, find unknown escape…

Error message

While parsing a quoted scalar, find unknown escape character.

What it means

Inside a double-quoted scalar, a backslash introduces an escape sequence that must be a recognized YAML escape (\n, \t, \\", \x41, \u0041, etc.). ScanBlockScalar's quoted-scalar escape handling throws this SyntaxErrorException when the character after the backslash is not in the simpleEscapeCodes table and not a valid numeric escape.

Solutions

  1. Use forward slashes or double the backslashes in double-quoted strings: "C:\\Users\\test".
  2. Switch the value to single quotes, where backslash is literal: 'C:\Users\test' and '\d+' need no escaping.
  3. Use only valid YAML escapes in double quotes: \0 \a \b \t \n \v \f \r \e \" \\ \N \_ \L \P \x.. \u.... \U.........
  4. Escape regex backslashes explicitly: "\\d+" instead of "\d+".
  5. Check the reported column: the character right after the offending backslash identifies which escape is invalid.

Example fix

// before (invalid \U / \d escapes)
path: "C:\Users\test"
pattern: "\d+"

// after
path: "C:\\Users\\test"
pattern: "\\d+"
Defensive patterns

Strategy: validation

Validate before calling

static bool OnlyValidYamlEscapes(string yaml)
{
    var valid = new HashSet<char>("0abtvfre \"\\/N_LP\t\n".ToCharArray());
    int i = 0;
    while ((i = yaml.IndexOf('\\', i)) >= 0)
    {
        char next = i + 1 < yaml.Length ? yaml[i + 1] : '\0';
        if (next != 'x' && next != 'u' && next != 'U' && !valid.Contains(next)) return false;
        i += 2;
    }
    return true;
}

Try / catch

try
{
    var obj = deserializer.Deserialize<T>(input);
}
catch (YamlException ex)
{
    throw new FormatException($"Unknown escape sequence near {ex.Start.Line}:{ex.Start.Column}: {ex.Message}", ex);
}

Prevention

When it happens

Trigger: Double-quoted strings containing Windows paths or regexes with bare backslashes, e.g. "path: "C:\Users\test"" (\U followed by unexpected chars) or "pattern: "\d+"" — \d is not a YAML escape. Thrown while scanning the escape sequence.

Common situations: Windows file paths pasted into double-quoted YAML values, regex patterns like "\d+" or "\w" written in double quotes, and shell scripts or JSON-ish habits ('\/' is not special here) applied to YAML.

Related errors


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

Appendix: source

Thrown at sources/core/Stride.Core.Yaml/Scanner.cs:1659

                                break;

                            case 'u':
                                codeLength = 4;
                                break;

                            case 'U':
                                codeLength = 8;
                                break;

                            default:
                                char unescapedCharacter;
                                if (simpleEscapeCodes.TryGetValue(escapeCharacter, out unescapedCharacter))
                                {
                                    scanScalarValue.Append(unescapedCharacter);
                                }
                                else
                                {
                                    throw new SyntaxErrorException(start, mark, "While parsing a quoted scalar, find unknown escape character.");
                                }
                                break;
                        }

                        Skip();
                        Skip();

                        // Consume an arbitrary escape code.

                        if (codeLength > 0)
                        {
                            uint character = 0;

                            // Scan the character value.

                            for (int k = 0; k < codeLength; ++k)
                            {
                                if (!analyzer.IsHex(k))

View on GitHub (pinned to 96fad776d2)