title: How can my ViewData be null, but expandable in the debugger?
body: <p>Just came across an interesting effect while debugging a View. The scenario is easy to reproduce - I have a breakpoint in a <code>View</code>, in the Watch window I add <code>ViewBag.ViewData</code> and the value is <code>null</code>. However, if I just add <code>ViewBag</code> and expand the object, I can see the <code>ViewData</code> and it is not <code>null</code>. I can also successfully expand it and see its properties.</p>
  
  <p>Can anyone explain whether it's a bug or what causes this behavior?</p>
  
  <p><img src="https://i.stack.imgur.com/60muo.png" alt="ViewBag.ViewData in Watch window"></p>
  
  <p><strong>EDIT</strong></p>
  
  <p><code>ViewBag.ViewData</code> is actually <code>null</code>. E.g. if I have this code in the View:</p>
  
  <pre><code>if (ViewBag.ViewData == null)
  {
      &lt;span&gt;ViewBag.ViewData is null&lt;/span&gt;
  }
  </code></pre>
  
  <p>it displays  the span. So the weird part is that I can expand it in the watch window and see the properties.</p>
  
  <p><strong>EDIT2</strong></p>
  
  <p>In response to @Darin Dimitrov's answer - I tried to reproduce this behavior with a custom test class and I get a <code>RuntimeBinderException</code> when trying to access the private property: <code>'SomeClass.SomeProperty' is inaccessible due to its protection level</code>:</p>
  
  <pre><code>public class SomeClass
  {
      private string SomeProperty;
  }
  
  dynamic dynamicObject = new SomeClass();
  if (dynamicObject.SomeProperty == null)
  {
      Console.WriteLine("dynamicObject.SomeProperty is null");
  }
  </code></pre>
  
  <p>In this case, shouldn't I be getting the same exception when accessing <code>ViewBag.ViewData</code> in the View (the line with <code>if (ViewBag.ViewData == null)</code>)?</p>