An item with the same key has already been added

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
After I installed Visual Studio 2012, a simple WPF DataGrid application crashes after editing all 3 columns. My coworkers havent installed VS2012 and on their machines, it works perfectly.
System.ArgumentException was unhandled<br/>
HResult=-2147024809<br/>
Message=An item with the same key has already been added.<br/>
Source=mscorlib<br/>
StackTrace:<br/>
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)<br/>
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)<br/>
at System.Collections.Generic.Dictionary`2..ctor(IDictionary`2 dictionary, IEqualityComparer`1 comparer)<br/>
at System.Windows.Controls.Primitives.Selector.InternalSelectedItemsStorage..ctor(InternalSelectedItemsStorage collection, IEqualityComparer`1 equalityComparer)<br/>
at System.Windows.Controls.Primitives.Selector.SelectionChanger.ApplyCanSelectMultiple()<br/>
at System.Windows.Controls.Primitives.Selector.SelectionChanger.End()<br/>
at System.Windows.Controls.SelectedItemCollection.EndUpdateSelectedItems()<br/>
at System.Windows.Controls.Primitives.MultiSelector.EndUpdateSelectedItems()<br/>
at System.Windows.Controls.DataGrid.MakeFullRowSelection(ItemInfo info, Boolean allowsExtendSelect, Boolean allowsMinimalSelect)<br/>
at System.Windows.Controls.DataGrid.HandleSelectionForCellInput(DataGridCell cell, Boolean startDragging, Boolean allowsExtendSelect, Boolean allowsMinimalSelect)<br/>
at System.Windows.Controls.DataGridCell.OnAnyMouseLeftButtonDown(MouseButtonEventArgs e)<br/>
at System.Windows.Controls.DataGridCell.OnAnyMouseLeftButtonDownThunk(Object sender, MouseButtonEventArgs e)<br/>
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)<br/>
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)<br/>
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)<br/>
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)<br/>
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)<br/>
at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e)<br/>
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)<br/>
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)<br/>
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)<br/>
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)<br/>
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)<br/>
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)<br/>
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)<br/>
at System.Windows.Input.InputManager.ProcessStagingArea()<br/>
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)<br/>
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)<br/>
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)<br/>
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)<br/>
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)<br/>
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)<br/>
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)<br/>
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)<br/>
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)<br/>
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)<br/>
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)<br/>
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)<br/>
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)<br/>
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)<br/>
at System.Windows.Threading.Dispatcher.Run()<br/>
at System.Windows.Application.RunDispatcher(Object ignore)<br/>
at System.Windows.Application.RunInternal(Window window)<br/>
at System.Windows.Application.Run(Window window)<br/>
at System.Windows.Application.Run()<br/>
at DataGridUnhandledException.App.Main() in C:CadSourcesTestDataGridUnhandledExceptionDataGridUnhandledExceptionobjx86DebugApp.g.cs:line 0<br/>
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)<br/>
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)<br/>
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br/>
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br/>
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)<br/>
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)<br/>
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br/>
at System.Threading.ThreadHelper.ThreadStart()<br/>
InnerException: <br/>

This is the code:
Xaml:
<pre class="prettyprint <Window x:Class="DataGridUnhandledException.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525
<Grid>
<DataGrid ItemsSource="{Binding Foos}"
SelectionMode="Single"
CanUserAddRows="False"
AutoGenerateColumns="False
<DataGrid.Columns>
<DataGridTextColumn Header="A" Binding="{Binding A, UpdateSourceTrigger=PropertyChanged}" />
<DataGridTextColumn Header="B" Binding="{Binding B, UpdateSourceTrigger=PropertyChanged}" />
<DataGridTextColumn Header="C" Binding="{Binding C}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>[/code]
<br/>
code behind:
<pre class="prettyprint using System.Collections.Generic;

namespace DataGridUnhandledException
{
public partial class MainWindow
{
public List<Foo> Foos { get; set; }

public MainWindow()
{
InitializeComponent();

Foos = new List<Foo> { new Foo() };
DataContext = this;
}
}

public class Foo
{
public string A { get; set; }
public string B { get; set; }
public string C { get; set; }

public override int GetHashCode()
{
return (A + B).GetHashCode();
}
}
}[/code]
Installing vS2012 (with R#7) was the only change I can remember. I now have VS2010 and VS2012 on my system. This shouldnt be the problem!?<br/>
<br/>


View the full article
 

Similar threads

Back
Top