UTF8 and data section string literals are limited to 65535 unique strings
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
**Version Used**: 10.0.100-rc.1.25451.107
**Steps to Reproduce**:
Run this file-based app:
```cs
#!/usr/bin/env dotnet
using System.Buffers.Text;
var file = Path.Join((string)AppContext.GetData("EntryPointFileDirectoryPath")!, "Program", "Program.cs");
Directory.CreateDirectory(Path.GetDirectoryName(file)!);
Console.WriteLine($"Generating '{file}'");
using var writer = new StreamWriter(file);
for (int i = 0; i < 65536; i++)
{
writer.Write("M(\"");
writer.Write(Base64Url.EncodeToString(BitConverter.GetBytes(i)));
writer.Write("\");");
writer.WriteLine();
}
writer.WriteLine("static void M(string s) { }");
```
That will generate `Program/Program.cs`.
Add `Program.csproj`:
```csproj
Exe
net10.0
enable
enable
$(Features);experimental-data-section-string-literals=0
```
And `dotnet run` that project.
**Expected Behavior**: Succeeds.
**Actual Behavior**: Fails with `Unhandled exception. System.TypeLoadException: Internal limitation: too many fields. at Program.$(String[] args)`
**Note**: Changing the number of unique string literals to 65535 succeeds, so that's the limit.
Originally reported by @peng5545 in https://github.com/dotnet/roslyn/issues/85413#issuecomment-3343171503.
Contributor guide
Assessment
This issue has not been assessed yet.