title: Exception: Invalid Cast after 2 years
body: <p>My VS2005 web application was working fine for the last two years. But today it suddenly started throwing exception of Invalid Cast.</p>
  
  <p>My code is:</p>
  
  <pre><code>int DistID = (int) this.Session["DISTRIBUTOR_ID"];
  </code></pre>
  
  <p>This line worked fine for more than two years.</p>
  
  <p>But now it suddenly started throwing exception of invalid cast. I checked in debug mode</p>
  
  <pre><code>this.Session["DISTRIBUTOR_ID"]
  </code></pre>
  
  <p>had valid int value of 1234.</p>
  
  <p>I solved the problem by changing my code to:</p>
  
  <pre><code>int DistID = Convert.ToInt32(this.Session["DISTRIBUTOR_ID"]);
  </code></pre>
  
  <p>But my boss asked me why this error occurred all of a sudden.</p>
  
  <p>Can anyone answer this question?</p>