Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# compile error: "No logical space left to create more user strings"

Tags:

c#

.net

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?

like image 800
Roman Starkov Avatar asked Sep 01 '09 13:09

Roman Starkov


2 Answers

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.

like image 93
Martin v. Löwis Avatar answered Oct 04 '22 00:10

Martin v. Löwis


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.

like image 25
paxdiablo Avatar answered Oct 04 '22 00:10

paxdiablo