title: Cannot perform runtime binding on a null reference, But it is NOT a null reference
body: <p>using: MVC 4, ASP.NET Razor</p>
  
  <p>I'm getting an error that looks like it shouldn't be possible. It tells me that i'm using a null-reference, States, but clearly it is being set. </p>
  
  <p>Controller:</p>
  
  <pre><code>public ActionResult Index()
  {
      Dictionary&lt;int, string&gt; states = new Dictionary&lt;int, string&gt;()
      {
          { -1, "a"},
          { 0, "b"},
          { 1, "c"},
          { 2, "d"},
      };
  
      //assigning states
      ViewBag.States = states;
  
      foreach (KeyValuePair&lt;int, string&gt; de in ViewBag.States)
      {
          Debug.WriteLine(de.Key);
      }
      return View();
  }
  </code></pre>
  
  <p>The View: </p>
  
  <pre><code>&lt;div class="search-input"&gt;
      &lt;select&gt;
          @foreach (KeyValuePair&lt;int, string&gt; de in ViewBag.States)
          {
              &lt;option value="@de.Key"&gt;@de.Value&lt;/option&gt;
          }
      &lt;/select&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The error: </p>
  
  <pre><code>Cannot perform runtime binding on a null reference
  Line 54: @foreach (KeyValuePair&lt;int, string&gt; de in ViewBag.States)
  </code></pre>