Raw string literals — the """...""" form that arrived in C# 11 — look like they must leave some trace in the compiled assembly. They let you paste JSON, SQL, regex, or a file path with no escaping at all, strip the indentation for you, and keep the newlines. Surely something that clever is recorded in the metadata?
It is not. A raw string literal, an old-fashioned verbatim @"..." string, and a plain "..." with escapes all compile to exactly the same thing: one ldstr instruction pointing at one entry in the #US (user-string) heap. The triple-quote syntax, the indentation rules, the newline handling — all of it runs at compile time and produces an ordinary string constant. By the time the bytes hit disk there is nothing "raw" left to find. That makes raw string literals a perfect lens for two questions a decompiler has to answer: where do string constants actually live, and when the source form has been erased, which form should you rebuild? This post walks both using Glass.NET.
What the source looks like
Here is a method returning a small blob of text that would be miserable to write as a normal string — it has single quotes, double quotes, a backslash, and line breaks:
static class Report
{
public static string Banner() => """
It's "ready".
Path: C:\tmp
""";
}
Three things happen at compile time, and all three are purely lexical. The newline immediately after the opening """ is removed, and so is the newline before the closing """. The whitespace to the left of the closing delimiter sets the common indentation that is stripped from every content line — here eight spaces, so the content de-indents to the left margin. And inside the literal there is no escape processing at all: the backslash in C:\tmp is a literal backslash, and the quotes are literal quotes. What is left is a single string value:
It's "ready".
Path: C:\tmp
That value — a string of 25 characters including one embedded \n — is the only thing the compiler carries forward. The """ delimiters have done their job and are gone.
There is no "raw" in the IL
Open the method in the Glass IL view and the whole feature collapses into one instruction:
.method public hidebysig static string Banner () cil managed
{
.maxstack 8
IL_0000: ldstr "It's \"ready\".\nPath: C:\\tmp"
IL_0001: ret
}
ldstr loads a string constant. The disassembler prints it with C-style escapes — \", \n, \\ — because that is how a tokenised listing shows a value, but those escapes are the disassembler's rendering, not something stored in the file. Write the identical text three different ways in source:
"It's \"ready\".\nPath: C:\\tmp" // plain, escaped
@"It's ""ready"".
Path: C:\tmp" // verbatim
"""
It's "ready".
Path: C:\tmp
""" // raw
…and all three compile to the same ldstr pointing at the same heap entry. The choice between them is a source-level readability decision that the compiler resolves and discards. This is the central fact for decompilation: the quoting style is not metadata. It cannot be recovered, only re-chosen.
Where the string actually lives: the #US heap
The operand of ldstr is a metadata token whose high byte is 0x70. That table id means user-string heap, and the low three bytes are a byte offset into the #US stream — one of the named heaps in the managed metadata, alongside #Strings (identifiers), #Blob (signatures and constants), and #GUID. So IL_0000: ldstr really encodes something like ldstr 0x70000001, and 0x000001 is where in #US the characters begin.
The #US heap stores each string in a compact, self-describing shape defined by ECMA-335: a compressed length prefix, then the characters as UTF-16 (little-endian, two bytes each), then a single terminal flag byte. The length prefix counts the bytes that follow, which is 2 × charCount + 1 — the +1 is that trailing flag. Take a tiny two-character string, A' (an A and an apostrophe), to see every byte:
The bytes are 05 41 00 27 00 01. The leading 05 is the compressed length — five bytes follow. 41 00 is A in UTF-16LE, 27 00 is the apostrophe. The final 01 is the flag: the runtime sets it to 1 when any character is outside a "plain" set — anything with a non-zero high byte, or one of a handful of special code points including 0x27 (the apostrophe) and 0x2D (hyphen). Our apostrophe trips it, so the flag is 01. A pure-ASCII string like "ready" would carry a 00 flag instead. The real Banner string follows the same scheme — compressed length, UTF-16 characters including the 0x000A newline, and a 01 flag because of that same apostrophe — just longer.
Two consequences fall out of this layout. First, strings in #US are deduplicated by value, so writing the same literal text in two methods, in two different quoting styles, yields two ldstr tokens pointing at one heap entry. Second, and the whole point here: the heap preserves the characters and nothing about the syntax. There is no bit that says "this was a raw string literal."
What Glass reconstructs — and how it chooses the quoting form
Because the syntax is gone, Glass does not recover a raw string literal; it re-chooses one. It reads the constant back from the heap and asks which C# quoting form renders those exact characters most readably. The logic follows a clear order:
- No newlines and no awkward characters → a plain
"..."literal. - Backslashes but no embedded double quotes and no newlines → a verbatim
@"...", which avoids doubling every backslash. - Embedded newlines together with quotes or backslashes → a raw string literal, which needs no escaping of either and shows the line structure directly.
Our Banner string hits the last case — it has a newline, both kinds of quote, and a backslash — so Glass rebuilds it as the raw form, picking a delimiter at least three quotes long (and longer if the content itself contained a run of """), then re-indenting the body under a closing delimiter:
static class Report
{
public static string Banner() => """
It's "ready".
Path: C:\tmp
""";
}
That is the same text you started with, but it is worth being precise about what happened: Glass did not read """ out of the file, because """ was never in the file. It reconstructed the most readable syntax that produces the bytes it found. Feed that reconstructed source back through the compiler and you get a byte-identical ldstr into a byte-identical #US entry. The round-trip is exact at the level that matters — the value — even though the surface syntax is a fresh, independent choice.
Reading it yourself
You can watch every stage of this in Glass from the command line:
glass decompile Report.dll --type Report --member Banner
glass decompile Report.dll --type Report --member Banner --il
The first command shows the reconstructed raw string literal; the second shows the single ldstr behind it. Then open the assembly in the Glass UI, switch to metadata navigation, and inspect the #US heap directly to see the length-prefixed UTF-16 bytes and the terminal flag for yourself — the apostrophe flipping that last byte to 01 is the kind of detail you only believe once you have seen the raw bytes.
Glass.NET is a free .NET decompiler for inspecting assemblies you have the right to inspect — your own builds, your dependencies, and third-party binaries you are licensed to analyse. Raw string literals are a small reminder of a large truth about decompilation: a decompiler reconstructs meaning, not keystrokes, and the best it can do — the thing Glass aims at — is rebuild the clearest source that compiles back to exactly what it read.
Top comments (0)