views:

864

answers:

12

I never had this problem before, but I reinstalled my computer recently and Visual Studio is not behaving well in debug for an ASP.NET site.

I am attaching visual studio 2008 to the w3wp process to debug a website. When I am debugging a method line by line with F10, sometimes visual studio will decide that it continues until it encounter a breakpoint... It's almost like if I pressed F5 to let it continue, but I press F10. For example if a method call is called more than once and there's a breakpoint at the beginning, while I am debugging line by line inside the method sometimes the execution will continue to the breakpoint at the beginning for no apparent reason so I lose all my debugging...

Anyone had this problem before?

Thanks,

+1  A: 

Cehck to make sure that your build mode is set to Debug not Release. In Release mode the optimizer is turned on and code can be rearranged or removed. Your breakpoints may make no sense from the perspective of the actual code.

tvanfosson
Release builds can be debugged just fine.
Brian Rasmussen
I am building in debug. All my dll have pdb in the bin folder. Never had this problem before with any projects.
EtienneT
@Brian -- release builds have symbols but code can be changed so that it is no longer synchronized exactly with the source lines. If it does code reordering, then it may appear to be jumping around in the source.
tvanfosson
@tvanfosson - I read your answer a little too fast. It is just that I have seen a few people suggest that you can't debug release builds.
Brian Rasmussen
+1  A: 

This almost sounds like the behaviour you get when debugging while having several threads or requests going on in parallell, alternatively if your method makes recursive calls. Are you sure this is not what happens?

Fredrik Mörk
I don't have any recursive calls. For example, the method where I had the problem this morning was on the row data bound event for a GridView.
EtienneT
A: 

You aren't using multiple threads are you? That could cause this behaviour.

And do you have this problem in different projects, or just in a single project?

Cloud
+3  A: 

You're probably debugging an assembly with an out of date PDB file, or perhaps the code has changed and wasn't recompiled.

In any case, it sounds like you have a mismatch somewhere between:

  • code
  • dll
  • pdb

(and as another guy noted, make sure you're building in Debug, not Release).

Ben Scheirman
If I check my configuration manager, everything is configured to be built in Debug. (all the projects).
EtienneT
A: 

Line by line debugging is F11 (Step Into), not F10 (Step Over).

Step Over will skip debugging on any methods you call.

R. Bemrose
great minds think alike, you beat me to the submit button :P
BenAlabaster
This is not the behavior I am having. It's almost like sometimes (not always) when I press F10 it behave just like if I pressed F5 to let the execution continue.
EtienneT
A: 

Alternative thought - have you tried using step into (F11) instead of step over (F10). If you're finding that method calls appear to be "skipped", it's possible that you're executing over the next line without actually stepping into it...

BenAlabaster
The behavior is not like F11, it's like if I pressed F5 to let the execution continue.
EtienneT
+6  A: 

I have the same problem, whenever I press step-into or step-over it continues to execution as if I pressed F5. Debugging is working only if I put a break point on every line I wish to evaluate. Is anyone else experiencing this besides me and the poster?

I've tried re-installing VS and everything but that didn't help. Furthermore, debugging does work in some other projects, to be specific WinForms projects, and when I press step into on the webservice call and "attach", debugging still works as it should.


OK, Update... I have found that my problem lies with Optimizations in compilation. I had optimizations turned on in debug configuration.

Make sure you uncheck that for debug configuration on all your projects and their references.

Also try: http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/f3fcb4fb-8a08-4fa0-8d58-9ed6f3eb1193

DKarter
A: 

Make sure your line endings are consistent. Windows likes CR/LF. Sometimes it gets confused about what line it is on if they aren't consistent.

jeffamaphone
A: 

Workaround found here http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/f3fcb4fb-8a08-4fa0-8d58-9ed6f3eb1193:

1) Open Visual Studio but do not open any projects.

2) Start the Task Manager (Ctrl+Shift+Esc) and navigate to the “Processes” tab.

3) Right-click on devenv.exe and select “Set Affinity…” (this option is only available on multi-processor or multi-core machines).

4) Uncheck every CPU except one and click OK.

5) Open your project and debug as normal.

Silverlight tools are not fixing the problem and the other patch provided in this forum thread either. This is the only working workaround I found yet.

EtienneT
No it's not working...
EtienneT
A: 

hi I am getting wrong answer when i debug my code with F5 but getting the right answer when i debug the same code with F10. Please help.

test
+5  A: 

The patch for this issue is here: http://code.msdn.microsoft.com/KB957912/Release/ProjectReleases.aspx?ReleaseId=1796

KB957912 - Update for Visual Studio 2008 SP1 Debugging and Breakpoints

jmcd
This just saved my life. I was having the same problem (stepping was unreliable on some projects) and after applying the fix F10 started working as it should.
Bruno Lopes
+1  A: 

I had the same issue after rebuilding my computer. After searching for answers, I found this thread. The solution for me was the hotfix found on MSDN, noted by a user in this thread.

http://code.msdn.microsoft.com/KB957912/Release/ProjectReleases.aspx?ReleaseId=1796

--Notable discussion--

MSDN does also have a great topic discussion, also noted by a user in this thread, with some workaround and a link to the patch.

social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/f3fcb4fb-8a08-4fa0-8d58-9ed6f3eb1193

I have seen a post where the following line of code was placed at the beginning of Page_Load(...) method. Personally this was not an option for me, but if you are comfortable with this being a fix for your problem and it works...

Response.Cache.SetCacheability(HttpCacheability.NoCache);

My setup: - Windows XP pro - Pentium 4 3.0GHz HyperThreaded - VS 2008 Professional Edition - .NET Framework 3.5 SP1 - SQL Server 2008 - Development language: c#

Chris R