我已经编写并测试了一个 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)
我承认在处理像这样的异常时我是个初学者。文本对我来说没有多大意义,我不确定调试它的最佳方法,因为我无法让错误在我的机器上发生。
任何人都可以告诉我问题是什么,或者建议我最好的调试方法吗?非常感谢任何帮助!
最佳答案
显然,您在主窗体加载事件处理程序上使用了一个 DataRowCollection
对象,而这个 DataRowCollection
对象是空的(即不包含任何行)。表单加载事件处理程序似乎假定它不会为空。
我建议您在 MainForm_Load
的左大括号上设置一个断点 (F9) 并单步执行(F10 或 F11)您的代码,直到找到代码尝试使用 DataRowCollection< 的位置
.
关于c# - 异常处理帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1829131/