Visual Studio 2008 调试器 - 函数评估怪异
我正在为一个更大的应用程序开发一个插件,我遇到了以下代码的奇怪问题。当在发布模式或没有断点的调试模式下运行时,一切都很好。但是当我在下面的代码片段附近放置断点时,我收到错误。看起来调试器会预先评估 if 块内的代码,从而导致错误,尽管实际上从未到达该代码。
请注意,索引器会在内部检查不正确的索引,并向主应用程序触发事件。主应用程序通过显示一个对话框并自行关闭来处理此错误事件。我无法更改主应用程序,也无法修改索引器(尽管我认为抛出异常而不是触发事件可以工作)。
int a = GetA(); // returns 0
if (a == 1)
{
_manager[a - 1][ColumnName.Name] = "X"; //Manager has an indexer returning a DataRow.
}
if (a == 2)
{
_manager[a - 1][ColumnName.Name] = "Y";
}
当我在“工具”->“选项”->“调试”中禁用“启用属性评估和其他隐式函数调用”时,它工作得很好。您有任何想法如何解决这个问题吗?我不想要此错误消息,但我也不想失去调试器评估的便利性。
[编辑]我重写了描述。
[更新] 我临时更改了索引器内的代码以引发异常,将事件委托给上层错误处理层,这有所帮助。 VS调试器吞掉了异常,因此所有副作用都停止了(错误处理层没有显示消息框)
所以问题是:
除了:
1)永久从弹出到上层的事件更改为异常
2) 取消选中“启用属性评估和其他隐式函数调用”
I'm developing a plugin for a bigger app and I encountered a strange problem with the following code. When run in Release mode or in Debug with no breakpoints everything is fine. But when I put a breakpoint somewhere near the snippet below I get an error. It looks like debugger pre-evaluates the code inside the if blocks causing an error altough this code is never actually reached.
Please note that the indexer internally checks for incorrect indexes and fires an event way up to the main application. The main app handles this error event by showing a dialog box and closing itself. I can't change the main app and I can't modify the indexer (altough I think throwing an exception instead of firing an event could work).
int a = GetA(); // returns 0
if (a == 1)
{
_manager[a - 1][ColumnName.Name] = "X"; //Manager has an indexer returning a DataRow.
}
if (a == 2)
{
_manager[a - 1][ColumnName.Name] = "Y";
}
When I disabled the "Enable property evaluation and other implicit function calls" in Tools->Options->Debugging it worked perfectly. Do you have any ideas how to work-around this? I don't want this error messages but I also don't want to lose the debugger evaluation convenience.
[EDIT] I re-wrote the description.
[UPDATE] I temporarily changed the code inside the indexer to throw an exception insted of delegating an event to the upper error-handling layer and it helped. VS debugger swallowed the exception so all side effects stopped (no message boxes were displayed by the error handling layer)
So the question is:
Is there a third option beside:
1) Permanently changing from an event being popped-up to upper layer to an exception
2) Unchecking 'Enable property evaluation and other implicit function calls'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否控制 _manager 实例的类的实现?您是否尝试过在其上添加 [DebuggerBrowsable(Never)] 属性?它应该对调试器隐藏该属性。
Do you control the implementation of the class that _manager is an instance of? HAve you tried putting [DebuggerBrowsable(Never)] attribute on it? It should hide that property from the debugger.