If you debug web applications frequently, you probably see this message in Visual Studio a lot. You set a breakpoint and attach to process, but the breakpoint is not active. If you hover over it, you will see this message:
The breakpoint will not currently be hit. The source code is different from the original version.
To begin, let me explain why you got this message.
You made a change to a method, view, class, etc, but you didn’t build the project before attaching to w3wp.exe. That’s all. Note, it’s best to just use ‘Build Solution‘ rather than ‘Rebuild Solution’. I’ve had times where I tried a Rebuild but nothing changed. I can’t quite explain it as anything other than a VS oddity.
Alternatively, you may get this message if you did build the project successfully. In that case, go to your web application and run the method/view, and VS should activate the breakpoints for you. In other words, sometimes you need to begin execution for VS to act correctly.
Now, onto that second part of the message…
To allow the breakpoint to be hit when the source code is different, right-click on the breakpoint, choose ‘Location…’, and turn on ‘Allow the source code to be different from the original version’.
Do NOT allow the source code to be different from the original version.
There may be some weird situation where you actually want it to be different, but I don’t know of one. This is kind of like in VS 2010, where the build fails, and VS asks you if you want to run the application anyway… same weirdness level.
If you DO set allow the source code to be different, your breakpoints will be active, but they won’t highlight the entire line.. causing all kinds of debugger oddities and bugs.
Take this example…
Sure, your breakpoint works now, but it’s not going to run anything past ‘products’, which causes an exception in the debugger. This can get even more weird as you continue debugging. Oh, and building won’t do a thing.
So, things to remember:
- Always build before attaching
- Never allow the source code to be different