Print Page | Close Window

Simple Delete problem

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1780
Printed Date: 21-Apr-2026 at 5:49am


Topic: Simple Delete problem
Posted By: orcities
Subject: Simple Delete problem
Date Posted: 04-May-2010 at 2:09pm
When I try and delete an entity using CurrentItem.EntityAspect.Delete() it throws an error:
Key cannot be null. Paramter name: key.
 
Before running the delete the item state is added. After the error the item state is unattached.
 
Why the error?



Replies:
Posted By: WardBell
Date Posted: 04-May-2010 at 7:42pm
Who is throwing the error? DevEx? DevForce? What is the full error?  What are the characteristics of the entity being deleted (its key and its foreign keys); we will set the FKs null if they are nullable.
 
I'm guessing this is the CONTROL complaining ... that is holding a copy of the now detached object and trying to do something with it. If I'm correct, the proper sequence is to remove the entity from the Control's "ItemsSource" and then call delete on it.
 
But I am guessing.


Posted By: orcities
Date Posted: 05-May-2010 at 7:30am
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()
 
 


Posted By: WardBell
Date Posted: 05-May-2010 at 1:48pm
So you've found a DevExpress bug and you should report it to them
 
     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)
...
 
Why is it their bug? Because they should be impervious to anything we do, almost no matter how wrong headed.

I do not understand why you cannot remove the item from the collection maintained by your VM. You'll want to figure that out. That appears to be the precipitating event in this exception, btw. Looks like a DevExpress issue again.
 
Happy to work with them and you to figure out what to do. I'm not trying to dump on them. But I don't
 
That doesn't help you in the meanwhile.
 
Removing the collection from the control is not something you want to do from within the VM. In principle you can replace the collection returned from the VM property to which the grid binds ... and do so entirely within the VM. However, that is likely to cause more problems as any control listening will reset itself ... and users will not like the consequences.
 
Suggest you experiment with other objects and the grid to find out what DevExpress likes and what triggers it to dislike something. Does it object to removing all objects of any kind? What happens when you detach rather than delete a DevForce object (use the manager's Remove method)?
 
Sorry to throw it back at you. I'm just not seeing yet how DevForce is contributing to the problem.
 


Posted By: orcities
Date Posted: 05-May-2010 at 2:01pm
tx Ward for explaining. Sometimes it is hard to tell which 3rd party product is causing the problem. I have found a handful of bugs with DevExpress that I am waiting for them to update.


Posted By: WardBell
Date Posted: 05-May-2010 at 2:15pm

I want to reiterate that I'm not trying to blame someone else. I'm happy to work with you and them to get it solved and will take responsibility for our part in the drama. But right now, I don't know where to begin ... because the error is coming from action taken by DevExpress after we innocently proceed with our deletion logic.

Keep us in the loop.


Posted By: orcities
Date Posted: 05-May-2010 at 2:16pm

Nope was gonna tell them you blamed them .....




Print Page | Close Window