dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.91k stars 4.01k forks source link

Fixed in https://github.com/dotnet/roslyn/pull/37915 #40371

Closed rogeriorlima3 closed 4 years ago

rogeriorlima3 commented 4 years ago

Fixed in https://github.com/dotnet/roslyn/pull/37915

Originally posted by @gafter in https://github.com/dotnet/roslyn/issues/37572#issuecomment-521501564


Guys, This was not fixed, we are facing the same error.

rogeriorlima3 commented 4 years ago

We are trying to use a big theme in an .aspx: in a web forms project. We have a huge legacy VB.Net project, that works perfectly (we need to improve UX of this web system) If we write the content of index.html (above referenced), in a default.aspx page, then the error appears.

gafter commented 4 years ago

https://github.com/dotnet/roslyn/pull/37915 did indeed reduce memory consumption from quadratic to linear. It did not remove the constraints of the assembly file format of the maximum amount of string literals an assembly may contain. You are hitting that limit and that is what the compiler is telling you.

It may be possible for us to increase that limit, but it would be a multiyear effort. If that's what you're asking for, please submit a separate feature request.

rogeriorlima3 commented 4 years ago

Do not trust MS. Ok, we will move to Java.... no problem :)

gafter commented 4 years ago

@rogeriorlima3 Java's class file format is even more restrictive in the size of its constant pool.

In the .NET assembly format, a metadata token into the string table is a 4-byte value, the first byte of which identifies the table (in this case the string table), and the remaining 3 bytes indicates the offset to the string. That is why the aggregate strings in an assembly are limited to about 10 million characters.

In the Java assembly format, a constant pool entry for a string is indicated by an offset into the constant pool. This offset is designated by the class file format specification to be a "u2", in other words two bytes or 16 bits. That is why the aggregate strings in a class are limited to about 60 thousand bytes.

Admittedly, this is not an apples-to-apples comparison. Many Java classes can be in the same program, and each class has its own limit, but all of the C# classes of a "program" go together into the same assembly and so share the limit.

Having said that, the metadata writer we use in the Roslyn compilers limit the amount of string literals to a smaller value than necessary (about 10 million characters instead of 15 million characters). We can try to increase that limit to see if it helps your application.

Please follow up in https://github.com/dotnet/roslyn/issues/40820.