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

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


当前回答

我在将一个项目从netcoreapp2.0升级到netcoreapp2.2后遇到了这个问题。

我只是通过编辑.csproj文件中的TargetFramework条目来做到这一点,而忽略了对launch.json进行更改。

"program": "${workspaceFolder}/src/MyProject/bin/Debug/netcoreapp2.0/MyProject.dll"

这意味着VS Code总是加载旧的2.0版本的项目。我在删除/bin和/obj中的所有内容后才发现它,然后它根本不会运行,直到我在上面的路径中发现2.0。

其他回答

注意vs中的“Output”窗口,它会告诉你加载了哪些程序集以及何时加载。您可能会看到正在加载文件夹中某个位置的程序集的旧版本。

例如,如果您有多个程序集,并且当前正在尝试插入其中一个支持程序集,CLR将处理程序集解析,这可能会加载您在项目中引用的程序集文件以外的另一个程序集文件。

有一个几乎察觉不到的设定为我解决了这个问题。 如果有一个特定的源文件没有命中断点,则可以将其列在

解决方案资源管理器 右键单击解决方案 属性 公共属性 调试源文件 "不要找这些源文件"

出于某种我不知道的原因,VS 2013决定在那里放置一个源文件,随后,我无法在该文件中点击断点。这可能是“源代码与原始版本不同”的罪魁祸首。

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.

在我的例子中,我忘记在我声明模板函数的头文件中包含“stdafx.h”。

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

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