title: Adding an item to a dictionary results in a NullReferenceException
body: <p>The following code has only thrown a NullReferenceException a handful of times over the last several months, but I'm not exactly sure why. The code isn't mine, but it looks pretty straight forward to me.</p>
  
  <pre><code>Type pageType = page.GetType();
  
  if (_pages.TryGetValue(pageType, out value))
      return value;
  
  // The following line throws the exception
  return _pages[pageType] = new MyPage(_section.Pages[page]);
  </code></pre>
  
  <blockquote>
    <p>[NullReferenceException: Object
    reference not set to an instance of an
    object.]
    System.Collections.Generic.Dictionary<code>2.Insert(TKey
    key, TValue value, Boolean add) +210
    System.Collections.Generic.Dictionary</code>2.set_Item(TKey
    key, TValue value) +11</p>
  </blockquote>
  
  <p>The only thing I can think of is that <code>pageType</code> is null when it's being used as a dictionary key, but apparently <a href="https://stackoverflow.com/questions/2201007/can-object-gettype-ever-return-null">that is not possible</a>.</p>
  
  <p>The code that calls it is simple: </p>
  
  <pre><code>protected override void OnLoad(EventArgs e)
  {
      base.OnLoad(e);
      _mypage = GetPage();
  }
  </code></pre>
  
  <p>I also thought that the error might be with the <code>_section.Pages</code>, but section is never null and never sets anything. If <code>.Pages[page]</code> returns null, the <code>MyPage</code> constructor simply returns. So what am I missing?</p>