title: Exception on accessing a class in Web API
body: <p>I am encountering a weird behavior. My Web API suddenly cannot be used because of this exception:</p>
  
  <pre><code>[ArgumentNullException: Value cannot be null.
  Parameter name: String]
     System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer&amp; number, NumberFormatInfo info, Boolean parseDecimal) +14198596
     System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +177
     Dota2IoT.Server.Models.ViewModels.NatMappingManager..cctor() +112
  
  [TypeInitializationException: The type initializer for 'Dota2IoT.Server.Models.ViewModels.NatMappingManager' threw an exception.]
     Dota2IoT.Server.MvcApplication.Application_Start() +223
  </code></pre>
  
  <p>And this is the constructor of <code>NapMappingManager</code>:</p>
  
  <pre><code>    private ConcurrentDictionary&lt;int, NatMappingViewModel&gt; mappings;
  
      private NatMappingManager()
      {
          this.mappings = new ConcurrentDictionary&lt;int, NatMappingViewModel&gt;();
      }
  </code></pre>
  
  <p>Previously, I didn't even call <code>NapMappingManager</code> from the Global.asax <code>Application_Start</code>, but I think it may be because of some concurrent. However, now I try to call:</p>
  
  <pre><code>// Initialize the NAT
  Models.ViewModels.NatMappingManager.Instance.ToString()
  </code></pre>
  
  <p>So the constructor can be called, but the same error happens. What's wrong with it? Did I do something with the code, or a bug from <code>ConcurrentDictionary</code>?</p>
  
  <p>EDIT: The exception does not happen on my local machine. It only happens on my Azure VM (Window Server 2012) server.</p>
  
  <p>EDIT to clarify for the correct answer:</p>
  
  <p>This is the code that causes the problem (I do not have explicit static constructor):</p>
  
  <pre><code>    private static readonly int MaxDeviceNumber = int.Parse(ConfigurationManager.AppSettings["MaxDeviceNumber"]);
      private static readonly int MinDeviceNumber = int.Parse(ConfigurationManager.AppSettings["MinDeviceNumber"]);
  </code></pre>