asp.net-mvc 未命中 Visual Studio 断点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21582022/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio breakpoints not being hit
提问by My Stack Overfloweth
I'm working with an ASP.NET MVC project that seems to be having some issues when attaching to the IIS process (w3wp.exe). I'm running the solution and IIS 8.5 on my own local machine so I wouldn't think that this has anything to do with our network. What's strange to me is that I'm able to hit the breakpoints on any other solution I debug locally.
我正在处理一个 ASP.NET MVC 项目,该项目在附加到 IIS 进程 (w3wp.exe) 时似乎存在一些问题。我在自己的本地机器上运行解决方案和 IIS 8.5,所以我认为这与我们的网络没有任何关系。令我感到奇怪的是,我能够在本地调试的任何其他解决方案上找到断点。
The issue I'm having exactly is that the breakpoints turn to red, hollow circles and never get hit. Usually the fix for this is a Clean/Rebuild of the solution but this hasn't worked. I've confirmed the code is being updated by adding "throw new Exception" to a page and ensuring it shows the exception. Again, this problem is only happening with this one solution. Any other solution I run the debugger with works fine. I've also tried restarting the app pool, the website, IIS, and also my computer.
我真正遇到的问题是断点变成红色的空心圆圈并且永远不会被击中。通常对此的修复是解决方案的清理/重建,但这并没有奏效。我已经通过向页面添加“抛出新异常”并确保它显示异常来确认代码正在更新。同样,这个问题只发生在这个解决方案中。我运行调试器的任何其他解决方案都可以正常工作。我还尝试重新启动应用程序池、网站、IIS 以及我的计算机。
A few of the articles I read mentioned that anti-virus programs can block a remote debugger from accessing the process. However, the entire setup is contained on my local machine so it doesn't sound like that would be the issue. It does concern me a bit though because we recently hired a new IT guy that's been making a lot of changes to everyone's machine.
我读过的一些文章提到防病毒程序可以阻止远程调试器访问进程。但是,整个设置都包含在我的本地机器上,所以听起来这不是问题。不过这确实让我有点担心,因为我们最近聘请了一位新的 IT 人员,他对每个人的机器进行了大量更改。
One other point to add that's unique about this web application is the binding in IIS. The binding is "*" in order to leverage some custom functionality related to subdomains.
要补充的另一点是此 Web 应用程序的独特之处在于 IIS 中的绑定。绑定是“*”以利用与子域相关的一些自定义功能。
In the meantime, I'll continue to look for a solution but if anybody has any ideas what may be causing this one solution to not debug properly I'd really appreciate it.
与此同时,我将继续寻找解决方案,但如果有人有任何想法可能导致此解决方案无法正确调试,我将不胜感激。
EDIT: Found a solution that suggested deleting the ASP.NET temporary files. No luck.
编辑:找到了建议删除 ASP.NET 临时文件的解决方案。没运气。
回答by My Stack Overfloweth
Solved. Ended up being an incorrect configuration selected in the debug menu. I had mistakenly switched it to a release configuration that could not load the symbols for the document. Switched it to a debug configuration and the breakpoints hit just fine now.
解决了。最终在调试菜单中选择了不正确的配置。我错误地将其切换到无法加载文档符号的发布配置。将它切换到调试配置,断点现在很好。
To add on to what Abacus mentioned below, it could also be a web.config transform that is messing with your build. In our case, we have Release configurations that remove the debugattribute from the web.config's compilation section. Below is a screenshot of an example and Visual Studio's dropdown list of build configurations.
要添加到下面提到的 Abacus 内容,它也可能是一个扰乱您的构建的 web.config 转换。在我们的例子中,我们有debug从 web.config 的编译部分中删除属性的Release 配置。下面是示例和 Visual Studio 的生成配置下拉列表的屏幕截图。
NOTE: Also make sure your Platform is correct along with the configuration. In my case, Dev.Debug|Mixed Platformsdoes not correctly build the solution but Dev.Debug|Any CPUwill.
注意:还要确保您的平台与配置一起正确。就我而言,Dev.Debug|Mixed Platforms没有正确构建解决方案,但Dev.Debug|Any CPU会。
回答by Javier Rodriguez
Enable 'Managed Compatibility Mode'. Go to Tools->Options->Debugging and enable Managed Compatibility Mode.
启用“托管兼容模式”。转到工具->选项->调试并启用托管兼容模式。
回答by Anselm
I struggled forever trying to fix this. Finally this is what did it for me.
我一直在努力解决这个问题。最后,这就是为我所做的。
SelectDebug->Options->Debugging->General
选择调试->选项->调试->常规
TickEnable .NET Framework source stepping.
勾选启用 .NET Framework 源步进。
(This may be all you need to do but if you are like me, you also have to do the ones stated below. The below solution will also fix errors where your project is loading old assemblies/.pdb files despite rebuilding and cleaning.)
(这可能是您需要做的所有事情,但如果您像我一样,您还必须执行下面所述的操作。尽管重建和清理,但以下解决方案还将修复您的项目加载旧程序集/.pdb 文件的错误。)
SelectTools -> Options -> Projects and Solutions -> Build and Run,
选择Tools -> Options -> Projects and Solutions -> Build and Run,
Untickthe checkbox of "Only Build startup projects and dependencies on Run",
取消勾选“仅在运行时构建启动项目和依赖项”,
SelectAlways Buildfrom the "On Run, when project are out of date" dropdown.
从“运行时,当项目过期时”下拉菜单中选择始终构建。
回答by kroolk
I know this is not the OPs issue, but I had this happen on a project. The solution had multiple MVC projects and the wrong project was set as startup.
我知道这不是 OP 问题,但我在一个项目中发生了这种情况。该解决方案有多个MVC项目,并且错误的项目被设置为启动。
I had also set the configuration of the project(s) to just start process/debugger and not open a new browser window.
我还将项目的配置设置为仅启动进程/调试器而不打开新的浏览器窗口。


So on the surface it looks as if the debugger is starting up, but it does so for the wrong process. So check that and keep in mind that you can attach to multiple processes also.
所以从表面上看,调试器似乎正在启动,但它是针对错误的进程启动的。因此,请检查并记住您也可以附加到多个进程。
Silly mistake that left me scratching my head for about 30 minutes.
愚蠢的错误让我挠了大约 30 分钟。


回答by legui
Right click on your project, then left click Properties, and select the Webtab.
右键单击您的项目,然后左键单击Properties,然后选择Web选项卡。
Verify whether the correct server is selected for your case:
验证是否为您的案例选择了正确的服务器:
IIS Local
IIS Express
IIS本地
IIS Express
回答by Brent
The issue was resolved by unchecking the
该问题已通过取消选中
Properties > Build > Optimize Code
属性 > 构建 > 优化代码
setting on the web page properties screen (under General).
网页属性屏幕上的设置(在常规下)。


回答by Rahul
Go to Visual Studio Menu:
转到 Visual Studio 菜单:
Debug -> Attach to Process
调试 -> 附加到进程
And then click the Selectbutton, as in the image below:
然后点击选择按钮,如下图:


Then make sure the "Automatically determine the type of code to debug" option is selected, like this:
然后确保选择了“自动确定要调试的代码类型”选项,如下所示:


回答by mayank
In my case this solution is useful:
在我的情况下,此解决方案很有用:
Solution: Disable the "Just My Code" option in the Debugging/General settings.
解决方案:禁用调试/常规设置中的“仅我的代码”选项。
Reference: c-sharpcorner
回答by Sean Anderson
回答by Anand Joshi
One of my projects in my solution was set to Releasemode. I changed it back to Debugmode, and the breakpoints are hitting now.
我的解决方案中的一个项目设置为发布模式。我把它改回调试模式,现在断点正在命中。

