问题
Trying to debug a controllers action method, and when I attach to process the debug icon goes hollow and says the 'current breakpoint will not be hit'
But I am doing a response.write
at that point and when the page renders it does output the test text.
So that section is indeed being executed, why does debug mode not work?
回答1:
Your source code may be different than the version of the corresponding process that you are attaching to. Your other process may also be built in release mode, i.e., there is no debug info.
回答2:
There are a few reasons why you may see this message:
- You are attached to the wrong process
- You are attached to the right process but the AppDomain hasn't loaded the assembly yet
- You are attached to the right process but you have forgotten to build so the source code and the PDB file are out of sync
回答3:
I've noticed this happen when using reflection and dynamically loading .dll projects. If the code isn't specifically reference (i.e. you are using interface animal but dynamically loading implementations of animal such as cat/dog) it will say it won't hit the breakpoint, but actually does.
回答4:
I do not like to play with knives but the only thing that worked for me involves editing the .csproj file itself. So, unload the project file, edit it by cutting and pasting the three asp.net files so that they are together in the ItemGroup. However, sometimes it is necessary to go further as explained here: http://carnotaurus.tumblr.com/post/4130422114/visual-studio-debugging-issue-with-files-of-the-same - Also, I give a list of other proposed solutions that did not work for me. I hope it helps.
回答5:
Another reason is when you attach to the process to quickly.
For example, when I attach to Excel to debug a VSTO add-in (I am using Add-In Express), if I Build, then Start > Run > Excel, then quickly press Ctrl+Alt+P to attach to process, then press E to highlight Excel and press Enter I see this, before Excel has loaded:

However, if I give Excel a couple of seconds to load and then press Ctrl+Alt+P, notice the Title is showing:

The result is Breakpoints will be hit.
回答6:
It also tells me your source code is different from the version but it is not true. I build the whole solution, then attach to process, but still it says the breakpoints won't be hit because the source code is different. Maybe it is a bug?
来源:https://stackoverflow.com/questions/1517311/reason-for-vs-net-current-breakpoint-will-not-be-hit-warning