I am trying to compile a one-off "script", an autogenerated C# program. This program contains 120,000 different string literals. The C# compiler can't build this, saying:
Unexpected error writing metadata to file '<removed>' -- 'No logical space left to create more user strings.'
Is there a hard limit in .NET on the number of string literals one can have in a module? What is this limit? Is there any way around it?
There is a limit on the number of strings in an assembly, just as there are limits on the number of classes, fields, etc. Each of these is identified with a 32-bit metadata token, where the upper-most byte is a meta-type-code, and the lower bits are the individual data record. For strings, they actually identify an offset into the string heap, so you can have at most 2**24 bytes for strings, i.e. 16MiB. Not sure whether strings are stored in UTF-8 or UTF-16.
I have no idea of what the limits are in .NET but, if it is a resource limitation, I'd solve it the same way we solved running out of space in the bad old 64K-segment days.
Externalize the strings - put them in an external file and simply store the offsets (and lengths if they're not null terminated). When you need a string, load it from the file and use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With