Tech Off Post

Single Post Permalink

View Thread: FxCop vs Static Constructors
  • User profile image

    Hi All,

    FxCop displays particular vehemence towards static constructors: it actually displays vehemence towards a lot of things but time is short. The argument proposed by the FxCop documentation is that, "Initializing static data in explicit static constructors results in less performant code.", which is fair enough. But what if the static constructor is being used for more then just initialising static data?

    For example I use a static logging class and initialise the logger in the static constructor. The logger is thread safe and I prefer to have a one stop shop for logging to make it for application wide changes. But back to the original question, why does FxCop object to static constructors when they present a valid useful purpose? Is there a reason why thread safe static constructors should be avoided?