【问题标题】:NullReferenceException mysteryNullReferenceException 之谜
【发布时间】:2010-12-22 22:52:33
【问题描述】:

由于某种原因,当我的应用程序启动时,我得到了 System.NullReferenceException。真正奇怪的是异常框如何不指向任何代码行。我不知道是什么部分导致了问题。这是堆栈跟踪:

System.NullReferenceException 未处理 Message="对象引用未设置为对象的实例。" 来源="Microsoft.VisualBasic" 堆栈跟踪: 在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.MainFormLoadingDone(对象发送者,EventArgs e) 在 System.EventHandler.Invoke(对象发送者,EventArgs e) 在 System.Windows.Forms.Form.OnLoad(EventArgs e) 在 System.Windows.Forms.Form.OnCreateControl() 在 System.Windows.Forms.Control.CreateControl(布尔 fIgnoreVisible) 在 System.Windows.Forms.Control.CreateControl() 在 System.Windows.Forms.Control.WmShowWindow(消息和 m) 在 System.Windows.Forms.Control.WndProc(消息和 m) 在 System.Windows.Forms.ScrollableControl.WndProc(消息和 m) 在 System.Windows.Forms.ContainerControl.WndProc(消息和 m) 在 System.Windows.Forms.Form.WmShowWindow(消息和 m) 在 System.Windows.Forms.Form.WndProc(消息和 m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息和 m) 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam) 在 System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd,Int32 味精,Int32 wParam,Int32 lParam) 在 System.Windows.Forms.Form.SetVisibleCore(布尔值) 在 System.Windows.Forms.Control.set_Visible(布尔值) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 原因,ApplicationContext 上下文) 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 原因,ApplicationContext 上下文) 在 System.Windows.Forms.Application.Run(ApplicationContext 上下文) 在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() 在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() 在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(字符串 [] 命令行) 在 EEMSReports.My.MyApplication.Main(String[] Args) 在 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 在 System.AppDomain._nExecuteAssembly(程序集程序集,字符串 [] 参数) 在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,String [] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态) 在 System.Threading.ThreadHelper.ThreadStart()

有人以前看过这个或有什么建议吗?

提前致谢。

【问题讨论】:

  • EEMSReports 第 81 行有什么内容?
  • 我问由于:at EEMSReports.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
  • 您是否将 VS 设置为因公共语言运行时异常而中断?
  • 真是愚蠢的问题,但无论如何我可以打开一个显示行号的设置吗?
  • @Ragepotato:不完全确定。那个设置在哪里?

标签: .net visual-studio exception


【解决方案1】:

如果您希望在异常发生时能够调试应用程序,请创建一个在启动调试器时启动应用程序的项目(请参阅项目属性->调试 选项卡)。该项目不需要任何源代码。

然后,告诉调试器中断任何抛出的异常(请参阅调试->异常)并使用 F5 启动您的应用程序。

【讨论】:

    【解决方案2】:

    正如 Ben 在 cmets 中所说,空引用来自:

    17d14f5c-a337-4978-8281-53493378c1071.vb 中的 EEMSReports.My.MyApplication.Main(String[] Args):第 81 行

    这表示一个临时的编译器生成的文件。从内存来看,这可能是 C# 编译器中的一个错误,它会在尝试使用临时文件之前将其删除。但我会将 Visual Studio 设置为在未处理的异常上中断,然后查看抛出异常的位置。

    【讨论】:

      猜你喜欢
      • 2018-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      • 2016-08-18
      • 2015-01-23
      相关资源
      最近更新 更多