异常处理帮助

时间:2009-12-01 21:42:59

标签: c# winforms debugging exception

我已经编写并测试了一个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)

我会承认,在处理像这样的例外情况时,我是初学者。该文本对我来说没有多大意义,我不确定调试它的最佳方法,因为我无法在我的机器上发生错误。

任何人都可以告诉问题是什么,或者告诉我最好的调试方法吗?非常感谢任何帮助!

4 个答案:

答案 0 :(得分:6)

显然,您在主表单加载事件处理程序中使用了DataRowCollection对象,并且此DataRowCollection对象为空(即不包含任何行)。表单加载事件处理程序似乎假设为空。

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

答案 1 :(得分:3)

Visual Studio具有非常好的远程调试功能。如果您在同事的计算机上启动远程调试主机,则可以从您自己计算机上的IDE中连接到该正在运行的进程。我已经用了几次这个非常好的结果。

http://msdn.microsoft.com/en-us/library/y7f5zaaa(VS.71).aspx

答案 2 :(得分:1)

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

答案 3 :(得分:1)

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