title: ObservableDictionary for c#
body: <p>I'm trying to use following implementation of the ObservableDictionary: <a href="http://blogs.microsoft.co.il/blogs/shimmy/archive/2010/12/26/observabledictionary-lt-tkey-tvalue-gt-c.aspx" rel="noreferrer">ObservableDictionary (C#)</a>.</p>
  
  <p>When I'm using following code while binding the dictionary to a DataGrid:</p>
  
  <pre><code>ObserveableDictionary&lt;string,string&gt; dd=new ObserveableDictionary&lt;string,string&gt;();
  ....
  dd["aa"]="bb";
  ....
  dd["aa"]="cc";
  </code></pre>
  
  <p>at <code>dd["aa"]="cc";</code> I'm getting following exception</p>
  
  <pre><code>Index was out of range. Must be non-negative and less than the size of the 
  collection. Parameter name: index
  </code></pre>
  
  <p>This exception  is thrown in <code>CollectionChanged(this, new NotifyCollectionChangedEventArgs(action, newItem, oldItem)</code> in the following method:</p>
  
  <pre><code>private void OnCollectionChanged(NotifyCollectionChangedAction action, KeyValuePair&lt;TKey, TValue&gt; newItem, KeyValuePair&lt;TKey, TValue&gt; oldItem)
  {
    OnPropertyChanged();
  
    if (CollectionChanged != null) CollectionChanged(this, new NotifyCollectionChangedEventArgs(action, newItem, oldItem));
  }
  </code></pre>
  
  <p>The <code>index</code> param seems to correspond to <code>KeyValuePair&lt;TKey, TValue&gt; oldItem</code>.</p>
  
  <p>How can <code>KeyValuePair&lt;TKey, TValue&gt;</code> be out of range, and what should I do to make this work?</p>