c# - 异常处理帮助

标签 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)

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

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

最佳答案

显然,您在主窗体加载事件处理程序上使用了一个 DataRowCollection 对象,而这个 DataRowCollection 对象是空的(即不包含任何行)。表单加载事件处理程序似乎假定它不会为空。

我建议您在 MainForm_Load 的左大括号上设置一个断点 (F9) 并单步执行(F10 或 F11)您的代码,直到找到代码尝试使用 DataRowCollection< 的位置.

关于c# - 异常处理帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1829131/

相关文章:

c# - 如何在使用嵌套属性计算值的只读属性上触发 INotifyPropertyChanged

c# - DataGridView 捕获用户行选择

c# - 组合框按键事件处理程序

android - 调试时找不到局部变量

c# - Entity Framework 稍后在选择语句中使用已选择的值保存在新变量中

c# - 在便士竞标网站的架构方面需要帮助

java - JSP 信息页面调试助手

Android 堆栈跟踪没有提及我的代码

c# - C# 中的按位赋值运算符

c# - 将整数添加到名称中