在Visual Studio中调试时,有时我添加了一个断点,但它是空心的,VS说“断点目前不会被击中。”源代码与原始版本不同。”显然,这使我无法进行调试。
这条消息到底是什么意思?什么原始版本?如果我只是打开了解决方案,而没有对代码做任何更改,又怎么会有“原始版本”呢?
在Visual Studio中调试时,有时我添加了一个断点,但它是空心的,VS说“断点目前不会被击中。”源代码与原始版本不同。”显然,这使我无法进行调试。
这条消息到底是什么意思?什么原始版本?如果我只是打开了解决方案,而没有对代码做任何更改,又怎么会有“原始版本”呢?
当前回答
帮助我的步骤(VS Community 2017, 15.9.11)。
请注意,执行以下步骤后将丢失断点。
右键单击类文件 选择排除 项目 右键单击该项目 选择“添加和现有文件” 导航到选择相关的类文件
其他回答
问题是调试信息与程序集不同步。解决方法很简单:
转到你的bin文件夹 删除.pdb文件 重建
应该能成功!
(奇怪的是,不丢弃.pdb文件的重新构建并不总是有效。我可以看到修改的日期正在更新,但仍然在链的某个地方(VS2013调试器,IIS,程序集缓存)没有检测到此更改)
对于一个类似的问题,我做了如下处理:
取消选中Debug -> option -> General菜单中的“Enable Just My Code”选项
注意vs中的“Output”窗口,它会告诉你加载了哪些程序集以及何时加载。您可能会看到正在加载文件夹中某个位置的程序集的旧版本。
例如,如果您有多个程序集,并且当前正在尝试插入其中一个支持程序集,CLR将处理程序集解析,这可能会加载您在项目中引用的程序集文件以外的另一个程序集文件。
VS 2017的一些版本(结合。editorconfig)也有一个问题:从15.3开始,当文件的字符集与.editorconfig (utf8或utf8-bom)中的字符集不一致时,断点就不起作用了。
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.