This project has moved and is read-only. For the latest updates, please go here.


KeyNotFoundException when changing Series.ItemsSource


I want to bind a data table that contains a list of budgets (name & value column).
<v:Chart x:Name="BudgetChart"
     Title="Budget Distribution">
<v:PieSeries x:Name="PieSeries" 
             IndependentValueBinding="{Binding Path=CategoryName}"
             DependentValueBinding="{Binding Path=Value}"/>
I bind my data to the chart like this, and it works fine the first time.
void RefreshChart()
PieSeries.ItemsSource = dataTable;
My problem, is that if I call RefreshChart() a second time, I get the following exception:
KeyNotFoundException: The given key was not present in the dictionary.
Is there something I'm not doing right?

file attachments

Closed Mar 24, 2009 at 2:23 AM by davidans
Technically, this bug is for WPF Charting, not Silverlight Charting, and WPF Charting is completely unsupported...

That said, this bothered me and I investigated this issue today. I have just checked in fixes for the issue abrien identified as well as one other that I found along the way. I have verified that the demo application attached to this work item works correctly after my changes.

I will be blogging an update to the WPF Charting DLL in a day or two on my blog:

Thanks very much for the help!


JustinJosefAngel wrote Mar 21, 2009 at 10:40 PM

Hi, I can't repro this issue.
Can you please include a minimal and relevant repro of this issue? Maybe start a a new project and just add the bare bones required to show us this issue?

Without it, we can't do anything to help you.

-- Justin Angel
Microsoft Silverlight Toolkit Program Manager

abrien wrote Mar 21, 2009 at 10:56 PM

I've attached a test project. Click the "Replace ItemsSource" button once to see the pie chart properly refresh, and a second time to see it crash when the PieSeries.ItemsSource property is changed.

wrote Mar 21, 2009 at 10:56 PM

abrien wrote Mar 22, 2009 at 4:41 AM

Here's the callstack I get:

at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at System.Windows.Controls.DataVisualization.Charting.PieSeries.UpdateLegendItemIndexes()
at System.Windows.Controls.DataVisualization.Charting.PieSeries.RemoveDataPoint(DataPoint dataPoint)
at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.RemoveObject(Object dataContext)
at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.LoadDataPoints(IEnumerable newItems, IEnumerable oldItems)
at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.Refresh()
at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.OnItemsSourceChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at System.Windows.Controls.DataVisualization.Charting.DataPointSeries.set_ItemsSource(IEnumerable value)
at ToolkitTest.Window1.ButtonReplace_Click(Object sender, RoutedEventArgs e) in D:\Users\Anthony\Visual Studio 2008\Projects\ToolkitTest\Window1.xaml.cs:line 39

wrote Mar 24, 2009 at 2:23 AM

wrote Feb 22, 2013 at 2:53 AM

wrote May 16, 2013 at 1:35 PM