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

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


当前回答

也许dll是从GAC加载的。

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

gacutil -u YourDll

其他回答

我在将一个项目从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。

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

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

应该能成功!

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

我之前一直在摆弄我的csproj文件。所以在项目属性(VS 2013) > Web选项卡>服务器部分>[下拉],我有“IIS快速”选择当我以前有“本地IIS”选择。一旦我将设置修正为之前的设置,断点就可以工作了。

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.

尝试在运行调试模式时禁用和重新设置断点,而不是在启动调试模式之前禁用和重新设置断点。