手柄未初始化错误 [英] Handle is not initialized error

查看:203
本文介绍了手柄未初始化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF应用程序,我使用MVVM。我直接绑定一个DataGrid的视图模型进行更新,添加和删除。有没有按钮这些行动。这一切的伟大工程,通过绑定属性。除了一个问题。

I have a wpf app and I'm using MVVM. I've bound a datagrid directly to the viewmodel for update, add and delete. There are no buttons for these actions. it all works great through bound properties. Except for one issue.

如果用户关闭与DataGrid中我尝试未提交的更改视图和视图模型的descructor捕捉到这一点。然后调用添加或更新的方法。但是,当

if a user close the view with uncommitted changes in the datagrid I try and capture this in the descructor of the ViewModel. Which then calls the ADD or update method. But when the

Context.SaveChanges(); 

被称为我得到一个手柄未初始化内部异常。

is called i get a "Handle is not initialized" inner exception.

在DataContext不为空。我创建了的ViewModels基类的DataContext并关闭它在的ViewModels基类的析构函数。通过code步进显示了基类的析构函数没有被调用。

The Datacontext is not Null. I create the datacontext in the ViewModels base class and close it in the viewmodels base class destructor. Stepping through the code shows the base class destructor has not yet been called.

下面是我的堆栈跟踪。

 at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
 at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
 at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
 at System.Data.Objects.ObjectContext.SaveChanges()
 at InspectorGeneral.ViewModel.VMItemList.Update(ItemsList obj)
 at InspectorGeneral.ViewModel.VMItemList.Modify(ItemsList obj)
 at InspectorGeneral.ViewModel.VMItemList.set_SelectedListItem(ItemsList value)
 at InspectorGeneral.ViewModel.VMItemList.Finalize()

任何人都可以点我在正确的方向,为什么这行code失败。

Can anyone point me in the right direction why this line of code is failing.

关于

推荐答案

我试图在的敲定,也得到了同样的错误。

I tried to execute a database call in Finalize, and also got this same error.

拍摄出来最终确定是唯一选项​​。

Taking it out of Finalize was the only option.

这篇关于手柄未初始化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆