The error is thrown at the CurrentItem.EntityAspect.Delete call. The error is Key cannot be null. Paramter name: key. and stack is below.
You are correct the item is detached and I understand why it is complaining. The problem is that I am using the MVVM pattern and I have access to the collection. But when I try and remove from the collection it never returns. When looking in the Output window I see "The trhead '<No Name>' (0x...) has exited with code 0 (0x0)." where 0x... changes for each line.
I ended up having to remove from the control source in the view. Maybe you can answer. Is that ok when using MVVM. I know some code can go there but?
Stack:
at System.Collections.Specialized.ListDictionary.get_Item(Object key)
at System.ComponentModel.PropertyDescriptorCollection.Find(String name, Boolean ignoreCase)
at DevExpress.Wpf.Core.Native.BindingListAdapter.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e)
at System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list)
at System.ComponentModel.PropertyChangedEventManager.OnPropertyChanged(Object sender, PropertyChangedEventArgs args)
at IdeaBlade.EntityModel.EntityWrapper.OnPropertyChanged(PropertyChangedEventArgs e)
at IdeaBlade.EntityModel.EntityGroup.OnEntityChanged(EntityChangedEventArgs e)
at IdeaBlade.EntityModel.EntityGroup.RemoveEntity(EntityWrapper wrapper)
at IdeaBlade.EntityModel.EntityWrapper.Delete()
at IdeaBlade.EntityModel.EntityAspect.Delete()
at LOC.AMP.Foundation.ViewModel.SearchPageViewModel.DeleteItem() in C:\Development\CEMS2.0\MVVMLite\AssociationManagementPro\Foundation\LOC.AMP.Foundation\ViewModel\SearchPageViewModel.cs:line 147
at LOC.AMP.Demo.ViewModel.RolodexExampleViewModel.DeleteItem() in C:\Development\CEMS2.0\MVVMLite\AssociationManagementPro\UI\LOC.AMP.Demo\ViewModel\RolodexExampleViewModel.cs:line 99
at LOC.AMP.Foundation.ViewModel.SearchPageViewModel.<get_DeleteContactCommand>b__1() in C:\Development\CEMS2.0\MVVMLite\AssociationManagementPro\Foundation\LOC.AMP.Foundation\ViewModel\SearchPageViewModel.cs:line 172
at GalaSoft.MvvmLight.Command.RelayCommand.Execute(Object parameter)
at LOC.AMP.Demo.View.RolodexExampleView.Contact_DeleteRow(Object sender, RoutedEventArgs e) in C:\Development\CEMS2.0\MVVMLite\AssociationManagementPro\UI\LOC.AMP.Demo\View\RolodexExampleView.xaml.cs:line 45
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at LOC.AMP.Foundation.View.SearchControl.mGridControl_DeleteRow(Object sender, RoutedEventArgs e) in C:\Development\CEMS2.0\MVVMLite\AssociationManagementPro\Foundation\LOC.AMP.Foundation\View\SearchControl.xaml.cs:line 164
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at LOC.AMP.Foundation.View.BaseGridControl.ExecuteDelete(Object sender, ExecutedRoutedEventArgs e) in C:\Development\CEMS2.0\MVVMLite\AssociationManagementPro\Foundation\LOC.AMP.Foundation\View\BaseGridControl.xaml.cs:line 155
at System.Windows.Input.CommandBinding.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
at System.Windows.Input.CommandManager.ExecuteCommandBinding(Object sender, ExecutedRoutedEventArgs e, CommandBinding commandBinding)
at System.Windows.Input.CommandManager.FindCommandBinding(CommandBindingCollection commandBindings, Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
at System.Windows.Input.CommandManager.FindCommandBinding(Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
at System.Windows.Input.CommandManager.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.Input.RoutedCommand.ExecuteImpl(Object parameter, IInputElement target, Boolean userInitiated)
at System.Windows.Input.CommandManager.TranslateInput(IInputElement targetElement, InputEventArgs inputEventArgs)
at System.Windows.UIElement.OnKeyDownThunk(Object sender, KeyEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey)
at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled)
at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run()
at LOC.AMP.Shell.App.Main() in C:\Development\CEMS2.0\MVVMLite\AssociationManagementPro\LOC.AMP.Shell\obj\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()