当程序在 .NET IDE 中暂停时,是否可以执行此调试代码?
我有几个大量的数据结构导致我的 VB.NET 应用程序出现问题。引发异常并且应用程序暂停后,我想运行一些代码,例如:
For Each o As MyClass In myObjects
If o.property = "value" Then debug.print(o.id)
Next
来诊断问题。
问题是,立即窗口不允许我执行循环,并且 myObjects
集合包含太多对象,我无法手动找到我想要的有问题的对象。
当调试器暂停时如何找到这个对象?在 .NET IDE 中可以实现此功能或类似功能吗?
I have a couple of massive data structures that are causing problems in my VB.NET application. After an exception is thrown and the application pauses, I'd like to run some code like:
For Each o As MyClass In myObjects
If o.property = "value" Then debug.print(o.id)
Next
to diagnose the problem.
The problem is that the immediate window won't let me execute loops, and the myObjects
collection contains far too many objects for me to find the offending one I want manually.
How can I find this object while the debugger is paused? Is this, or something similar, possible in the .NET IDE?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够使用 IDE 中的立即模式窗口来执行类似的命令,但数据必须在调试器的当前范围内可用。
You should be able to use the Immediate mode window in the IDE to execute commands like that, but the data has to be available within the current scope of the debugger.
不,您不能直接从 IDE 执行此操作。不幸的是,解决这个问题的最简单方法是停止调试,在返回您要查找的对象的公共静态方法中编写循环,重新编译并运行,然后从“立即”或“监视”窗口调用该公共静态方法。
另一个更直接(但烦人)的技巧是在“立即”窗口中编写“
? myObjects
”,将结果复制粘贴到记事本中,然后在记事本中使用文本搜索(Ctrl+F)来查找您的对象。No, you can't do this directly from the IDE. Unfortunately, the easiest way to work around it is to stop debugging, write your loop inside a public static method that returns the object you are looking for, re-compile and run, and then call that public static method from the Immediate or Watch window.
Another more immediate (but annoying) trick is to write "
? myObjects
" in the Immediate window, copy paste the result into notepad, and use text search (Ctrl+F) in notepad to find your object.