Maximum number static fields allowed in mscorlib?

The maximum number of static fields allowed in mscorlib?

1020

Yep you read that right, an arbitrary 1020, not even a computer-scientisty power-of-2, like 1024. Static fields are scoped per AppDomain and this limitation is hardcoded in the native implementation of that class. Check out the Rotor source if you are interested (search for STATIC_OBJECT_TABLE_BUCKET_SIZE):

sscli20\sscli20\clr\src\vm\AppDomain.cpp

Have a guess how a colleague of mine, Brian Grunkemeyer, found this out today…

(This limitation is only in mscorlib – other assemblies do not have a limitation, or rather, have an insanely high limit that you should never hit)

Published Thursday, March 04, 2010 11:00 AM by David Kean

Comments

Friday, March 05, 2010 2:28 AM by Ooh

# re: Maximum number static fields allowed in mscorlib?

Hmm, he tried to add another one and suddenly ALL automated tests failed?

Wednesday, March 10, 2010 1:59 AM by Daniel Lidström

# re: Maximum number static fields allowed in mscorlib?

I had a look at AppDomain.cpp. What I can't understand is what motivates anybody to create source files of close to 10000 lines?