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

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


当前回答

在我的例子中,其他建议都不起作用,但是重新克隆我的存储库使这个问题消失了。

其他回答

在我的例子中,其他建议都不起作用,但是重新克隆我的存储库使这个问题消失了。

问题是调试信息与程序集不同步。解决方法很简单:

转到你的bin文件夹 删除.pdb文件 重建

应该能成功!

(奇怪的是,不丢弃.pdb文件的重新构建并不总是有效。我可以看到修改的日期正在更新,但仍然在链的某个地方(VS2013调试器,IIS,程序集缓存)没有检测到此更改)

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

This happen often also if you are using a file references to binaries (instead of project references to code in your project), and the compiled binary that you are referencing falls out of sync with the corresponding source code on your machine. This can happen because you downloaded a new version of the binary from source control without the new source code that went with it, or you have a few versions of the binary on your machine and are referencing an old copy, etc. If this is indeed the problem, it's a good reason to use project references as much as it practical.

工具 选项 调试 一般

取消选中“要求源文件与原始版本完全匹配”