在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.

其他回答

也许dll是从GAC加载的。

您可以从gac卸载dll,需要管理员权限。

gacutil -u YourDll

我在vs2017的32位版本中遇到过这种情况。

没有一个解决方案对我有效。我重新启动,我清除IDE文件,清洁构建的解决方案,从git回购和重建解决方案无效。

我从nuget中提取了一个64位依赖项,一旦我使用了程序集,源就不再被构建到最终的可执行文件中,而是构建了IDE缓存的源。

我删除了nuget配置,删除了引用的程序集,下载了源代码,手动构建log4net,对其进行了签名,将其添加到我的项目中的一个文件夹中,并对其添加了引用,然后我就可以再次进行调试了。

这是一个痛苦,我希望它能出现在答案列表中,让所有人都看到。

编辑:在构建过程中没有错误,尽管在IDE设置中打开了“构建错误提示”选项。

VS 2017的一些版本(结合。editorconfig)也有一个问题:从15.3开始,当文件的字符集与.editorconfig (utf8或utf8-bom)中的字符集不一致时,断点就不起作用了。

对我来说,解决方案隐藏在项目属性的高级构建设置中:

由于未知的原因,它被设置为none:将其设置为full会导致命中断点。

要进入此对话框,请打开项目属性,然后转到构建,然后选择高级…按钮在页面底部。

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