Repository navigation
Description
Found by the analysis of #46.
Problem
The identity an unnamed declaration's key is hashed over, and the stored value, are JSON written with JavaScriptEncoder.UnsafeRelaxedJsonEscaping (Declarations/Internal/DeclarationCodec.cs). That encoder escapes code points its runtime does not know as assigned, so the text for one declaration differs between runtimes. The key is permanent from 11.0.0 and the plan calls for canonical content.
Evidence
One console app, run on three runtimes, writing {"template":"{Name} <> ''"} (U+A7DB):
| Runtime | Written | First 16 hex digits of SHA-256 |
|---|---|---|
| 9.0.23 | '' |
fd9507928d9c46e4 |
| 10.0.15 | the character itself | ec1a164da6ed61b9 |
| 11.0.0 | the character itself | ec1a164da6ed61b9 |
22 BMP code points are escaped on .NET 9 and written raw on .NET 10: U+0897, 1B4E, 1B4F, 1B7F, 1C89, 1C8A, 2427–2429, 2FFC–2FFF, 31E4, 31E5, 31EF, A7CB–A7CD, A7DA–A7DC. Nothing differs between 10 and 11.
Consequence
A later runtime major that assigns more code points gives the same declaration another key and another value text: snapshot churn, another order from GetDeclarations, and a changed count from Redeclare for a declaration nobody changed. No DDL follows from it as long as the planner (#24) pairs declarations by descriptor and never by annotation name.
Since #46 the reader compares the stored value with what it read as JSON, not as text, so a value written by another runtime still reads.
Done when
The identity, and the value, are written by an escaper that uses no runtime data (only ", \ and U+0000–U+001F escaped), and a golden key for a template with a recently assigned character outside ASCII is held verbatim. This moves keys, so it has to land before preview.1 or with a decision on the keys already written.
Found while fixing, 2026-11-11
- The rule needs three more characters than JSON does. With U+2028 written as itself, the snapshot EF Core scaffolds does not compile (
CS1010, newline in constant): EF Core writes an annotation's value into a C# string literal and does not escape U+0085, U+2028 or U+2029, which end a line in C#. The old encoder happened to escape them. The rule is therefore:",\, everything below U+0020, and those three. - Half a surrogate pair was stored as U+FFFD, so two different strings became one. It is now refused.
- A property name cannot be written raw through
Utf8JsonWriter, so names are held to ASCII letters, digits and_, which no encoder escapes. - Measured: the escaper's output for every BMP character and one outside it is byte-identical on .NET 9.0.23, 10.0.15 and 11.0.0. Keys of declarations made of ASCII do not move.
Activity