Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
There are several errors related to declaring string constants or string literals.
- CS1009: Unrecognized escape sequence.
- CS1010: Newline in constant.
- CS1011: Empty character literal.
- CS1012: Too many characters in character literal.
- CS1039: Unterminated string literal.
- CS8997: Unterminated raw string literal.
- CS8998: Not enough starting quotes for this raw string content.
- CS8999: Line does not start with the same whitespace as the closing line of the raw string literal.
- CS9000: Raw string literal delimiter must be on its own line.
- CS9001: Multi-line raw string literals are only allowed in verbatim interpolated strings.
- CS9002: Multi-line raw string literals must contain at least one line of content.
- CS9003: Line contains different whitespace than expected.
- CS9004: Not enough quotes for raw string literal.
- CS9005: Not enough closing braces for interpolated raw string literal.
- CS9006: Too many opening braces for interpolated raw string literal.
- CS9007: Too many closing braces for interpolated raw string literal.
- CS9008: Sequence of '@' characters is not allowed.
- CS9009: String must start with quote character.
- CS9274: Cannot emit this string literal into the data section because it has XXHash128 collision with another string literal.
- CS9315: Combined length of user strings used by the program exceeds allowed limit. Adding a string literal requires restarting the application.
The following sections provide examples of common issues and how to fix them.
Incorrectly formed string literals
The following errors concern string and character literal syntax and common mistakes when declaring literal values.
- CS1009 - Unrecognized escape sequence.
- CS1010 - Newline in constant.
- CS1011 - Empty character literal.
- CS1012 - Too many characters in character literal.
- CS1039 - Unterminated string literal.
Common causes and fixes:
- Invalid escape sequences: An unexpected character follows a backslash (
\\). Use valid escapes (\\n,\\t,\\uXXXX,\\xX) or use verbatim (@"...") or raw string literals for content that includes backslashes. - Empty or multi-character char literals: Character literals must contain exactly one UTF-16 code unit. Use a single character like
'x'or a string /System.Text.Runefor characters outside the BMP. - Unterminated strings: Ensure every string or verbatim string has a matching closing quote. For verbatim strings, the final
"must be present; for normal strings ensure escaped quotes are balanced. - A string literal spans multiple lines of C# source.
Examples
// CS1009 - invalid escape
string a = "\\m"; // CS1009 - invalid escape \m
// Use verbatim strings or escape backslashes
string filename = "c:\\myFolder\\myFile.txt"; // escaped backslashes
string filenameVerbatim = @"c:\myFolder\myFile.txt"; // verbatim string
// CS1011 - empty character literal
// public char CharField = ''; // CS1011 - invalid: empty character literal
// CS1012 - too many characters in char literal
char a = 'xx'; // CS1012 - too many characters
// CS1039 - unterminated verbatim string
// string b = @"hello, world; // CS1039 - missing closing quote
For more information on literal strings and escape sequences, see the articles on verbatim strings and raw strings.
Incorrectly formed raw string literals
The following errors are related to raw string literal syntax and usage.
- CS8997 - Unterminated raw string literal.
- CS8998 - Not enough starting quotes for this raw string content.
- CS8999 - Line does not start with the same whitespace as the closing line of the raw string literal.
- CS9000 - Raw string literal delimiter must be on its own line.
- CS9001 - Multi-line raw string literals are only allowed in verbatim interpolated strings.
- CS9002 - Multi-line raw string literals must contain at least one line of content.
- CS9003 - Line contains different whitespace than expected.
- CS9004 - Not enough quotes for raw string literal.
- CS9005 - Not enough closing braces for interpolated raw string literal.
- CS9006 - Too many opening braces for interpolated raw string literal.
- CS9007 - Too many closing braces for interpolated raw string literal.
- CS9008 - Sequence of '@' characters is not allowed.
- CS9009 - String must start with quote character.
Check these common causes and fixes:
- Unterminated or mismatched delimiters: Ensure your raw string starts and ends with the same number of consecutive double quotes (
"). For multi-line raw strings, the opening and closing delimiter lines must appear on their own lines. - Indentation and whitespace mismatch: The indentation of the closing delimiter defines the trimming of common leading whitespace for content lines. Make sure content lines align with that indentation.
- Insufficient quote or
$counts for content: If the content begins with runs of quote characters or brace characters, increase the length of the delimiter (more") or the number of leading$characters for interpolated raw strings so content can't be confused with delimiters or interpolation. - Illegal characters or sequences: Avoid multiple
@characters for verbatim/raw combinations and ensure you use verbatim interpolated forms when combining interpolation with multi-line raw strings.
The following code shows a few examples of incorrectly formed raw string literals.
// Unterminated raw string (CS8997)
var s = """This raw string never ends...
// Delimiter must be on its own line (CS9000)
var t = """First line
More text
""";
For full syntax and more examples, see the language reference on raw string literals.
Literal strings in data sections
- CS9274: Cannot emit this string literal into the data section because it has XXHash128 collision with another string literal.
- CS9315: Combined length of user strings used by the program exceeds allowed limit. Adding a string literal requires restarting the application.
CS9274 indicate that your declaration can't be emitted in the data section. Disable this feature for your application. Debugging tools emit CS9315 after you changed string data in the data section while debugging and your app must be restarted.