在Visual Studio中调试时,有时我添加了一个断点,但它是空心的,VS说“断点目前不会被击中。”源代码与原始版本不同。”显然,这使我无法进行调试。

这条消息到底是什么意思?什么原始版本?如果我只是打开了解决方案,而没有对代码做任何更改,又怎么会有“原始版本”呢?


当前回答

如果您调试的进程包含多个appdomain,并且程序集都被加载到两个域中,其中一个正在加载旧副本(通常是动态加载的插件),断点可能看起来很稳定,但应该命中断点的线程位于旧程序集的appdomain中,并且从未命中。您可以在模块窗口中看到加载了哪些程序集及其路径。

其他回答

因为构建版本更改了(很可能您修改了源代码),所以重新编译解决方案并再次运行应用程序,之后它将到达调试断点。

如果您在调试构建配置中未选中DLL项目,那么您的新代码将永远无法构建!

转到构建—>配置管理器…(在VS2010中),并检查您正在尝试调试的代码的项目是否为当前构建配置进行了检查。

在某些情况下,重新编译和重新构建并不能帮助克服这个问题。 另一个潜在的解决方案是从解决方案资源管理器中删除带断点的源文件,然后重新添加它(例如通过从文件夹中拖放)。

在Windows 7、Visual Studio Express 2010下,如果已激活选项“为Windows XP SP3使用兼容性模式”,则可能会出现此错误。

我取消了这个选项,它再次完美地工作了。右键单击VS或可执行文件的快捷方式,选择属性,然后选择兼容性。

I suffered from this recently, and in my case I traced the problem back to something I was doing when testing: changing the system time. I'm not suggesting this is the case for everyone, but thought I'd mention it since it hasn't been mentioned already. It appears if you start moving the clock around between debug builds then it can get very confused about what order various files have been created it - I can only assume it is using file modified dates to determine if the source code is valid or not, and which binaries it needs to recompile.

这也是一个重新保存网页的选项。配置以碰撞其修改时间。