Tech Off Post

Single Post Permalink

View Thread: Static initializers and reflection
  • User profile image

    Calling all static constructors before calling entry point can be inefficient if there are a lot of them. More importantly, if you want to call all static constructors at startup you'll find that there's no particular ordering you can use.

    The basic requirement is that the static constructor (aka type initialized) of a type is called before any of the static fields of that type are accessed. This lazy initialization generates a particular ordering that you cannot reproduce at statup without some complicated or even impossible code analysis.

    You can read more details about this in section 10.5.3 of the ECMA-335 standard (