Investigation related to dotnet/aspnetcore#21787 Error CS8103 Combined length of user strings used by the program exceeds allowed limit. Try to decrease use of string literals.
- .NET 7.0.100-rc.1.* SDK (download from the installer repo)
In repo root:
- Run script
Generate-Pages.ps1
- Run
dotnet build
This repro includes an experiment using C# 11 Utf8 string literals to workaround the literal limit by using a custom Razor page base class that includes a method WriteUtf8Literal(ReadOnlySpan<byte> buffer)
that can be used to write literals out from their Utf8 byte literals rather than string literals. Updating the Razor compiler to support this natively for all literals might have a number of advantages.
-
Run script
Delete-Pages.ps1
in repo root -
Uncomment lines 5 and 7 in
LargeRazorStringLiterals/Pages/Generated/PageTemplate.cshtml
around the template placeholder:\5 @WriteUtf8Literal(@" 6 ***CONTENT HERE*** 7 "u8);
-
Run script
Generate-Pages.ps1
in repo root -
Run
dotnet build
in repo root