title: Static member variable not being initialized in Release - Compiler/clr bug?
body: <p>Expected output &amp; output I get in debug mode, and release mode under VS2010, .NET 4.0:  </p>
  
  <pre><code>bar construct
  main
  </code></pre>
  
  <p>Output in release mode <strong><em>not</em></strong> under the VS2010 debugger, and under WinDbg:  </p>
  
  <pre><code>main
  </code></pre>
  
  <p>Program does not exhibit this behavior on VS2005, .NET 2.0</p>
  
  <pre><code>using System;
  
  namespace static_init
  {
      public class bar
      {
          public bar()
          {
              Console.WriteLine("bar construct");
          }
      }
  
      class Program
      {
          public static bar blah = new bar();
  
          static void Main(string[] args)
          {
              Console.WriteLine("main");
              Console.ReadLine();
          }
      }
  }
  </code></pre>
  
  <p>Probably related:
  <a href="https://stackoverflow.com/questions/2925611/static-constructor-can-run-after-the-non-static-constructor-is-this-a-compiler">Static constructor can run after the non-static constructor. Is this a compiler bug?</a></p>
  
  <p><strong>Update</strong></p>
  
  <p>In my actual code constructor <code>bar()</code> initializes some interop code with C++ (unmanaged).  It needs to happen before anything else in this library - is there any way to ensure that without putting in an <code>init()</code> function that touches all of the statics (with side effects that aren't externally referenced)  in the library?</p>
  
  <p>Note for future searchers: I'm using SWIG, and this is an assumption that they made in their wrapper generation code.   <code>SWIGStringHelper</code> is the current offender, there may be more though.</p>
  
  <p><strong>Conclusion</strong></p>
  
  <p>Update to version 2.0 of SWIG, it puts in the static constructor as needed by newer version of .NET.</p>