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

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


当前回答

我已经试过提出的解决办法了,但不管用。

如果您有多个项目,请将要调试的项目作为启动项目。

其他回答

我只是重新装填,清理和重建我的作品。

当调试期间或调试会话之间的系统时间发生变化时,可能会发生这种情况,无论是通过编程方式、手动方式还是通过外部程序。

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.

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

如果您正在使用激活器,而设置断点的程序集尚未加载,则可以获得此消息。

一旦激活器加载程序集(假设程序集和调试符号是最新的),断点将被解析。查看调试菜单中的模块窗口是一个好地方。在那里您应该寻找您的文件所属的程序集。首先检查程序集是否加载。那么,从哪里装载的呢?然后,是符号文件加载。同样,符号文件从哪里加载?最后检查两者的版本。