user316117
user316117

Reputation: 8281

Breakpoints being moved Visual Studio 2010

I use breakpoints in debugging my C#/.Net programs. Very often I use many "When hit" breakpoints to display messages in the Output window and keep going, so I can examine what the program is doing while it's executing.

But I often find that after editing code my breakpoints get moved, producing spurious or incorrect results and I have to go and delete my old breakpoints and make new ones.

Searching for this on Stack Overflow I find other programmers having this problem when building in Release mode, but I'm building with a Debug configuration.

How do I make my breakpoints stay put?

Upvotes: 2

Views: 279

Answers (2)

Sarvesh Mishra
Sarvesh Mishra

Reputation: 2072

There are many ways to examine the execution of program. Make sure you are generating full Debug Info for your project. Also check that csproj.user, .suo files aren't set as Read Only.

enter image description here

If these thing doesn't work, for your case I suggest you to use some console based output providing methods.

Try this one

Console.WriteLine("Currently executing this...");

The console here is the output window of VS. Select Debug from 'Show output from:'. enter image description here

If you want to halt the execution, use this code

Console.WriteLine("Currently executing this...");
System.Diagnostics.Debugger.Break();

You should do conditional compilation of your code so that this doesn't get released with the final product. Console.WriteLine() will not cause any problem but System.Diagnostics.Debugger.Break() will break application.

Upvotes: 1

AFract
AFract

Reputation: 9690

  • Do you "share" files such as .csproj.user, .suo... with other developers of the project ?

If you are using a SCM exclude them from it, these files are not intended to be shared between different machines. To send them to another user with slightly different sources may cause this kind of funny mess.

More details about these files here : Best practices for Subversion and Visual Studio projects

  • This kind of thing could also happen if you manually edit files, outside of VS (with Notepad++ for example) : try to avoid this when you want to keep breakpoints at the right place, VS doesn't like it at all.

Upvotes: 5

Related Questions