title: Dictionary foreach KeyValuePair mystery
body: <p>Take this little piece of code</p>
  
  <pre><code>        NWN2GameAreaDictionary areaDictionary = app.Module.Areas;
  
          IEnumerator enumerator = areaDictionary.Values.GetEnumerator();
          enumerator.MoveNext();
          MessageBox.Show(enumerator.Current.GetType().Name);
  
          enumerator = areaDictionary.Keys.GetEnumerator();
          enumerator.MoveNext();
          MessageBox.Show(enumerator.Current.GetType().Name);
  
  
          foreach (KeyValuePair&lt;string, NWN2GameArea&gt; entry in areaDictionary)
          {
              MessageBox.Show(entry.Key);
              MessageBox.Show(entry.Value.Name);
          }
  </code></pre>
  
  <p>The NWN2GameAreaDictionary inherits all the way from IDictionary</p>
  
  <pre><code>public class NWN2GameAreaDictionary : OEIDictionaryWithEvents
  public abstract class OEIDictionaryWithEvents : DictionaryBase
  public abstract class DictionaryBase : IDictionary, ICollection, IEnumerable
  </code></pre>
  
  <p>When I run that code I get an output for the first MessageBox and second one, respectivly being: NWN2GameArea and string.  So any sane normal person would assume the foreach loop would work ... yet </p>
  
  <p>System.InvalidCastException: Specified cast is not valid.</p>
  
  <p>Why would that be .... so I tried with some other stuff and wanted to know the type of Keys and Values and I get KeyCollection and ValueCollection.  Yet when I want to cast to those types ... the compiler just states, hey buddy these types DO NOT EXIST .... aaargh ... this language is getting an exercise in frustration ... I should just stick to java.</p>
  
  <p>can anyone give me an explaination for this behaviour ?</p>