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

其他回答

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

检查解决方案中是否有多个具有该名称的文件。

这是我从别人那里接手的一个项目。在Controller.cs中,断点列表充满了行号,有些是活动的,有些不是。我找到了这个问题,并尝试了一些选项,但是当我双击断点时,它们将我带到解决方案中的不同项目。因为文件被称为相同,所以它们看起来是相同的,但实际上不是。答案当然是忽略这个警告,因为如果你要加载另一个文件,它们就会变得活跃。

对我来说;我的网站在默认网站(http://localhost/myapp/)下的IIS应用程序中运行,并且IIS应用程序的映射指向的磁盘路径与我正在处理的源代码不同。

解决;重新映射您的IIS应用程序到与您正在构建的源代码相同的路径。

(如果您在磁盘的不同位置运行同一个应用程序的多个版本,就会发生这种情况)

至:

Tools > Options > Debugging > General > unchecked "要求源 文件与原始版本完全匹配”

我发现当断点在不能被打断的行上时发生错误。我没有显示工具提示,是为了直接显示后面没有错误的行。