Archive for May, 2008

Initializing ThreadStatic fields

Saturday, May 17th, 2008

Yesterday a friend of mine came across a problem concerning the initialization of ThreadStatic fields. He always encountered a NullReferenceException while accessing those fields.
Here's a sketch of what he tried to do:
PLAIN TEXT
C#:

class Program

{

    [ThreadStatic]

    static StringBuilder aValue = new StringBuilder();

 

    static void Main(string[] args)

    {

        Program p [...]