This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, An unexplained error occurred and I'm unable to trace the cause. I'm trying to achieve updating a one-to-many relation via a combobox. This in itself is good, changing the combobox value will update my database. But whenever I navigate to another page the following error occurred: ObjectDisposedException, Cannot access a disposed object. The stack trace is giving no useful information. Stacktrace:
It seems the UnitOfWork (randomly) an Entity removes which is disposed. XAML-code:
Any help would be appreciated. Thanks! |
|
|
I would guess that somewhere in your binding the User.Physiotherapist is getting set to null. This is causing the User to be removed from a dependent collection which in turn is removing it from the unit of work. This could be happening because in the course of tearing down the combo box WPF is clearing or nulling the ItemsSource, which in turn is changing SelectedItem to null, which in turn is causing a spurious update to the bound Physiotherapist property. You should be able to verify or refute this theory by putting a breakpoint on the Physiotherapist setter just before navigating to a new page, and using Show External Code in the Call Stack window to see where the call to the setter is coming from (presumably somewhere within WPF). You will also want to know whether the ItemsSource is being set to null and if so when this is happening. If the guess is right, I'm not sure if there's an elegant resolution to this. Changing the ItemsSource so it uses a local viewmodel instead of relying on the hosting control might help, because it might be the unparenting of the containing UserControl that is clearing the ItemsSource. Otherwise, you might need to remove the SelectedItem binding (using BindingOperations.ClearBinding) before performing the navigation (which is really nasty because the ComboBox is in a DataTemplate). Knowing when the ItemsSource is being set to null might give you further ideas. Hope this is enough to get you on the trail of the problem -- let us know if we can provide any further info! |
|
|
Your guess is correct, when navigating the ItemsSource sets the User.Physiotherapist to null. I've solved it with a property in the ViewModel. This property will update the physiotherapist to its appropriated user. This was not LightSpeed related, sorry for bothering but thanks a million for the tip! For whom interested, I'll post the code below:
|
|