2009-12-01 124 views
3

我已经编写并测试了一个WinForms应用程序,并且在我的机器上一切都正常工作(我知道这是陈词滥调)。当我创建了一个安装项目和安装了一个同事的机器上,他收到以下消息:异常处理帮助

************** Exception Text ************** 
    System.IndexOutOfRangeException: There is no row at position 0. 
    at System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex) 
    at System.Data.RBTree`1.get_Item(Int32 index) 
    at System.Data.DataRowCollection.get_Item(Int32 index) 
    at MyApp.MainForm.MainForm_Load(Object sender, EventArgs e) 
    at System.Windows.Forms.Form.OnLoad(EventArgs e) 
    at System.Windows.Forms.Form.OnCreateControl() 
    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) 
    at System.Windows.Forms.Control.CreateControl() 
    at System.Windows.Forms.Control.WmShowWindow(Message& m) 
    at System.Windows.Forms.Control.WndProc(Message& m) 
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m) 
    at System.Windows.Forms.ContainerControl.WndProc(Message& m) 
    at System.Windows.Forms.Form.WmShowWindow(Message& m) 
    at System.Windows.Forms.Form.WndProc(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 

我承认我是一个新手,当涉及到处理这样的一个例外。这段文字对我来说并没有什么意义,我不确定调试这种方法的最佳方式,因为我无法在我的机器上发生错误。

任何人都可以告诉问题是什么,或者建议我调试这个最好的方法吗?任何帮助是极大的赞赏!

+0

你可以发布'MyApp.MainForm.MainForm_Load'的代码吗? – 2009-12-01 21:51:10

回答

6

显然,你正在使用一个DataRowCollection对象你的主表单加载事件处理程序,而这个DataRowCollection对象是空的(即不包含行)。表单加载事件处理程序似乎假定它将而不是为空。

我建议你通过代码在MainForm_Load的开启大括号上设置断点(F9),并通过代码设置步骤(F10或F11),直至找到代码尝试使用DataRowCollection的位置。

1

听起来像数据的差异 - 你试图通过一个不存在的索引来访问节点在树上......

1

您正在创建一个数据行集合,并使用collection[0]访问它,而不验证它是否至少有一个元素开头。也许你的coleague连接到一个没有行的空数据存储?