title: C# Cannot check Session exists?
body: <p>I get an error when I do the following:</p>
  
  <pre><code>if(Session["value"] != null)
  {
     // code
  }
  </code></pre>
  
  <p>The error i get is this:</p>
  
  <p>Object reference not set to an instance of an object.</p>
  
  <p>Why is this? I always check my session this way? I am using the MVC Framework, does this has something to do with it?</p>
  
  <p>EDIT:</p>
  
  <p>The code is in the constructor of a Controller:</p>
  
  <pre><code>public class MyController : ControllerBase
  {
      private int mVar;
  
      public MyController()
      {
          if (Session["value"] != null)
          {
              mVar= (int)Session["value"];
          }
      }
  }
  </code></pre>