How to enable break point in visual studio 2017 - c#

I am trying to put break point to web api service which is written in visual studio 2017.
However, I am unable to see the option to put break point.
I have used F9 and Alt+F9 to put breakpoint to my code.
Still its not working.
Kindly let me know how to enable break point in visual studio 2017

Try to talk your cursor to the extreme end of the code editor, very close to that place that as the line number. Then click it, you should see a red circle there. That is your breakpoint.

click on the left side of the line number. A red dot should appear

You can create breakpoints in Visual Studio in several ways. One way is to have your cursor on the line you want to have a breakpoint, and then press F9. You will see a red circle on the left indicating a breakpoint.
However, you can also click to the left of the line number you want to add a breakpoint on, and that will also create a breakpoint.
Example: https://learn.microsoft.com/en-us/visualstudio/debugger/media/dbg-tour-set-a-breakpoint.gif?view=vs-2019
Also, see this for reference: https://learn.microsoft.com/en-us/visualstudio/debugger/using-breakpoints?view=vs-2019

Related

How to set breakpoints to all lines in a c# file in visual studio?

I am working with Visual Studio 2015.
I have a big c# class file with lot of properties and methods. I want to set breakpoints to all possible lines (set and get of properties, methods) at once. How can I do that?
You could add Debugger.Break() on the end of every single line. Therefore you could use the search and replace function of visual studio and replace \n with Debugger.Break()\n (Remember activating the regular expression option). This would cause the debugger to break at every single line, even though you won't have an indicated breakpoint.
I don't think that there's a method to add normal vs breakpoints to every single line though, due to the fact that it's quite useless, considering that you normally just step through the code with F11.
I think you are looking for this,
steps to follow:
1) Add a break point on the first line of code you want to debug.
2) Run the application.
3) When you want to run the next line of code, Select Debug | Step Into
4) Repeat step #3 for each line of the code
With vim (vsvim) you can set a breakpoint, move down a line, then repeat however many times you like, eg:
{Escape}qq:vsc Debug.ToggleBreakpoint{Enter}jq100#q
will set breakpoints on the next 100 lines
edit: here is example video, wouldnt let me embed gif https://imgur.com/SFhlEr7
Step Into(F11) or use the Debugger.Break() or add breakpoint directly would be the workarounds for you, of course, I suggest you use the Step Into(F11) which was much more convenient.
If you could use the latest VS2017 version, it has a new feature "Run to Click" which is also a better workaround for you during debugging.
Actually you don't have to debug every line code, that's also the reason I suggest you use this new feature.
Run to Click: Simply click the icon next to a line of code while debugging to run to that line. No longer set temporary breakpoints or
perform several steps to execute your code and stop on the line you
want. Now while stopped at a break state under the debugger, the Run
to Click icon subtly appears next to the line of code that your mouse
is hovered over. Move your mouse to the icon and click the button, now
your code will run and stop on that line the next time it is hit in
your code path. Turn it off from Debug> Options > Enable Run to
Click.
Reference:
https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes
Open a feature request with Microsoft https://learn.microsoft.com/en-us/visualstudio/ide/suggest-a-feature?view=vs-2022
There should be a mode that visual studio can be put in so that it automatically stops on every line of code in a particular project. This would be VERY valuable when you attach the debugger to a pre-existing process and you don't know where in the app is the current point of execution is, ie: web apps where you do not know the entry point.

Multiplied breakpoints in Visual Studio [duplicate]

I recently started having problems with breakpoints in Visual Studio 2010. When I set a breakpoint and then start debugging, another breakpoint appears on some other line nearby. The screenshots below shows the editor after I set a breakpoint, as well as the breakpoints window:
As soon as I start debugging, the breakpoint duplicates, as seen in the following screenshots:
Why is this happening and how can I stop it?
It looks like there is a child breakpoint set up, as described in the following MSDN articles:
http://msdn.microsoft.com/en-us/library/b98cwcyw.aspx (Link dead, see
Child breakpoints VS 2010)
http://msdn.microsoft.com/en-us/library/02ckd1z7%28VS.71%29.aspx#vctskbreakpointswindowchildbreakpoints
Here is a similar question on StackOverflow, for which one of the answers contains a macro to remove child breakpoints. Perhaps that might work for you?
Disable/remove child Breakpoints?
Alternatively, deleting the parent breakpoint (which will also remove the children) and re-creating it might help to resolve the problem.
I suspect it is because of mismatched newline endings. I had similar issue - multiple lines were marked as breakpoint location (say, 10 lines). Later I found it was because of only \n or \r present, instead of CRLF sequence.
Use Save-As, select Save With Encoding.. option under Save button in SaveAs dialog box.
I had the same problem in VS 2008 and I resolved by getting rid of the duplicated .dll files in the compiling / debugging folders.
Please refer to my full response here: https://stackoverflow.com/a/50063517/3603386
Do you use F10 (step over) when debugging?
F9 is the shortcut to add/remove a breakpoint, you may be inadvertently hitting that.

Visual studio 2012 debugging - stop when the project/namespace is being hit

I am currently debugging large project, I put a breakpoint on the starting point of the application, but it takes forever to hold f10 until it gets into the location I want it to get.
Is there any way to tell the debugger to hold f10 until it gets to a project or the namespace that I want to stop it on?
just right click on your breakpoint, there are various options for filters, location, etc.
http://msdn.microsoft.com/en-us/library/5557y8b4.aspx

Prevent showing visual studio window when Breakpoint hits while debugging c#

When a breakpoints hits, the VS window is showed automatically and points to the line with the breakpoint. For my case that's not helping. Is it possible to prevent the VS studio window from showing when the breakpoint hits ? Thanks
EDIT: he problem is that I'm reading from a barcode scanner gun. While reading, the breakpoint hits thus switching to the VS window and some portion of the barcode is printed in the source file :) That's why I don't want it to switch to the VS window
If you set the breakpoint in the Visual Studio, you can change it to "tracepoint" by specifying "Continue execution" as "When hit".
If the breakpoint is present in the executable, it can be disabled as described in How to disable a programmatical breakpoint / assert?
You can start your application as Start Without Debugging or use (Ctrl + F5) for that.
Or If you want to debug, but not for a condition, you can provide the condition on breakpoints when to hit.

Step through a program backwards after an Exception has occurred - Visual Studio

Is there a way to step back through a program from the point where an error/Exception has occurred? Or look at the sequence in which the methods were called before the error occurred?
In the Ultimate versions of Visual Studio 2010 you can use Inellitrace to go back in the execution, as Dan Puzey mentioned.
However, in any version of Visual Studio you can still get a lot of information just from the call stack. It doesn't only show the calls that lead up to the current position, by double clicking on points in the Call Stack window you can jump to the point in the code where each method was called. The state of the stack is preserved, so you can even still see the values of local variables in the calling method.
If you have VS2010 Ultimate, the "Intellitrace" functionality allows you to do exactly that. It basically logs a huge amount of execution data (up to and including every method call & parameter made) and allows you to step back in time to examine variable values at those points.
You will see the trace in the Stack Trace (Call Stack Window in Visual Studio).
If you are using debugger you can drag and drop the yellow arrow to the previous lines of code to repeat the scenario. However, it does not always work.
Right click on the line of code to which you want to get back and select "Set next statement"
Another option is to drag the yellow arrow to the desired line.

Categories

Resources