The problem is that when I place a breakpoint and debug/run, the breakpoint moves by itself.
Before/whilst coding:
After clicking run/breakpoint hit:
Breakpoints typically work ok for me, but it seems that they sometimes randomly play up. I first had this ages ago with a VB project, and in the end, I bypassed the problem by removing the breakpoint and adding it somewhere else where it was still useful.
Whilst I could probably do the same again, and this is only the second time it has happened (that I remember), I don't really want to have to and would like to know what is actually wrong.
I have read through many similar questions here, but I cannot see an exact match and the answers do not help. I have tried - building, rebuilding, closing/reopening and cleaning.
I only provided a picture of the bit of code where it occurs, if you need anything else, please let me know.
It's because the debugger isn't able to break at that point. For example, the debugger can't break on auto-implemented properties, or at the header of a method; instead, it breaks at the first line of the method.
Also check to see if you had set the breakpoints in one mode (Debug) but are now in a different mode (like Release). This caused me some momentary angst.
I got this problem after Windows had inexplicably added 6 months to the current system date (and 1 hour to the time). I didn't correct this right away, so builds made before the correction looked more recent to Visual. This lead to running the wrong (older) build when debugging.
Since I couldn't find a "Clean Solution/Project" option, I had to manually delete all .pdb files in the solution. The problem was instantly fixed. I just hope there aren't any more files I might need to delete (I'm new to Visual and don't know much about how it works behind the scenes).
You can get this if the breakpoint is AFTER a return statement. Visual Studio will bounce the breakpoint to the closing brace (or "End Function" for VB.NET) because return is jumping out of the function.
Related
I'm having a problem in Visual Studio 2012/C# which is driving me crazy. I have a particular line of code in a C# file with NO breakpoint set. Every time this line should be executed the debugger interrupts the execution of my code like a breakpoint was set. The only difference i noticed is the arrow on the left hand side, indicating the current step. Usually this arrow is yellow (when a breakpoint is set). In my case it is grey.
I have been searching for a solution but did not find anything useful to this. I tried deleting all breakpoints, build project, rebuild project, clean project and it still appears.
Does anyone have the same problems and found a solution this?
normal arrow:
arrow in my case:
This line of code is currently executing, it calls something else, e.g. native code or .NET internal code and an exception happens there. You can see both arrows in the call stack window:
Perhaps you need to turn on "Show external code".
If you can't see the exception dialog, usually you can show it like this:
When I run my code within VS, when I enter certain methods, upon ending the application (closing the form) been debugged, VS does not end the debug session automatically forcing me to end it manually.
This doesn't always happen, the results are consistent with certain windows / classes loaded when the application is run within VS.
I want to know why this may be, I'm assuming its an indication of a file not been closed in my managed code or 'something' like that.
Why might this occur and how can I trace and fix it?
This would happen if your code keeps running after closing the window.
Pause the debugger after closing the window to find out what it's doing, then modify the code so that it stops running when you close the window.
On Debug menu, click "Detach All".
Hope that helps!
EDIT
Follow, SLak's advice, as that will go after the problem. My solution may only fix the symptom. I will leave the answer here just in case it is helpful to you though.
Good luck!
I want to completely remove "error list" from visual studio 2008, not disable it i want it gone. It annoys me to no end popping up endlessly, i guess i must be "doing it wrong" but w/e i just want to use VS without being alerted every other keystroke about some warning.
I've tried editing many different fields in the options (tools -> options) it has only slightly decreased the frequency of the error list popping up. I have also deselected errors, warnings, and Messages. and it pops up with nothing to display. unpinning it doesn't help either.
also upgrading to VS 2010 is not an option at this point.
Im looking for a solution something like the following: remove a dll or config file responsible for this
Also I still want the inline validation (the little squiggly marks, etc), but
the error list window annoys me.
I think this is probably exactly what you're wanting:
http://blogs.msdn.com/b/zainnab/archive/2010/05/16/hide-or-show-error-list-when-the-build-finishes-with-errors-vstiptool0022.aspx
You can change this behavior by going to Tools -> Options -> Projects
and Solutions -> General and deselecting the "Always show Error List
if build finishes with errors".
I'm guessing this will work with ASP.Net as well, since that's building on the fly.
I am using Visual Studio 2017, and I also have to cope with the useless, impossible-to-disable, annoyingly-in-your-face, and outright disturbing "Error List" window.
So, here is what I did:
Undock the "Error List" window to make it free-floating.
Resize it to the smallest size possible.
Move it out to some remote area of the screen where it is not so annoying.
And voila, problem solved ! (*1)
*1 Well, problem mostly solved. It will be completely solved when I abandon this dinosaur of an IDE.
My 'Error List' was constantly displaying also (VS2012). I also hate it.
I turned it off years ago, but today it just started appearing.
It was being caused a unreadable packages.config file. For some reason that reports it's fail state through the yukky 'Error List'.
Fixing the packages.config file stopped the 'Error List' from appearing.
for VS2017, select the "Build only" value from the drop down list in Error tab. Refer to the image below:
Hope this helps!
On Error tab, you have Errors / Warnings / Info buttons. Click on Errors button (de-press).
hope it helps.
I suggest turning off inline validation.
Yes, I know that you still want it. But, seriously, how important is it? It's trying to validate code that is half-written. How valuable can that be?
First of all, as-you're-typing code validation is distracting. It makes it harder to focus on the problem you are trying to solve. For example, writing a function with a non-void return will display the "not all code paths return a value" error continually until you get to the end of the function. In the meantime, the editor is telling you that there is a problem. I am sure that people learn to ignore these things over time (I have never kept the feature on for more than a few minutes after a new VS installation, so I don't know), but if you are actively ignoring something, then what good is it?
Second of all, any good that the validation would be capable of is unnecessary, because those errors will be brought to your attention at compile-time anyway. Having an uninitialized variable pointed out to you while you are thinking through the algorithm does not improve the quality of the code at all verses having it pointed out when you try to run the program. The variable is still going to be initialized either way. And there is an extremely high likelyhood that you are going to fix the problem before trying to run the code anyway.
So I just don't see the point of it. I suggest turning it off, and then your problem goes away.
UPDATE
As pointed out by #Charlie Kilian, there is a flaw in VS in which .aspx files are not validated at all, unless the "Show live semantic errors" option is enabled for C#, rather than validating those pages at compile-time as would be expected.
Therefore, editing aspx files will require turning this option back on for validation.
I guess I'll be going back-and-forth with it from now on. I hope they fix this in future versions of VS.
I still think that doing a semantic analysis and error-reporting on code that is actively being edited is a fool's errand. (Of course, I have also been known to write entire programs in notepad, just to see if I could get it to compile and run correctly the very first time without the crutch of Intellisense. It feels pretty awesome when it works.)
Selected answer is incorrect because unchecking "Always show Error List if build finishes with errors" does nothing to stop the dreaded Error List window from popping up on other errors, even if you change it to show only Build errors.
11 years later in Visual Studio 2022 it is still impossible to disable Error List window.
The only correct answer to the question "Completely remove error list from visual studio" is to uninstall Visual Studio itself which, thankfully, also removes Error List window.
Either that, or we should all get used to it, because Developer Gods from Microsoft want everyone to work in absolutely the same way as they do. Every workflow that differs from their own is wrong, and every thought that doesn't align with their grand vision is blasphemy.
It is One Microsoft Way or the highway.
I´m coming from a PHP background where my debugging "tools" are basically echo, var_dump and exit. While I know the importance of debugging, I never tried to use/learn a debugging tool.
Now I´m learning C# and I think I can´t really program without an extensive knowledge of this area.
So my question is: where can I learn what is and how to do debugging? I know what is a breakpoint (conceptually), but how to use it? How to use Step into and Step over? Basic things like that.
As a related question, there is anything like var_dump in C# (Visual Studio), where I can inspect any object.
I find very difficult and painful to do a foreach for every array/list to see the contents, specially now that I´m still learning the language.
Microsoft has an extensive guide on C# debugging in Visual Studio that might be helpful. VS has a lot of powerful debugging functionality; for example, rather than doing a foreach to see the contents of an array as you were describing, you could set a breakpoint (pausing the execution of the program) and select the variable you wish to see the contents of (array or list or whatever) and see what it contains, without having to write any extra code. Step Into and Step Over can be used to continue execution of the program but only incrementally so that you can continue to see how variables change, where the flow of execution currently is, etc.
This has been covered earlier on StackOverflow:
Best Visual Studio 2008 Debugging Tutorial?
So, your compiled applications can be run in a "debug" mode from which visual studio can monitor the internal workings of the application and even control it.
A break point can be placed just about anywhere in your code by clicking to the far left of the line (kinda in the margin of the visual studio text editor). When that line of code has been reached, the visual studio debugger will actually pause the execution of your program and bring you back to the editor where you can literally hover over a variable or object or whatever and see everything about it.
There is also a "Locals" window available that will give you the break down of all of your locally scoped items - this should pop up by default at the bottom of your screen when debugging.
In debug mode you can navigate the execution of your code line-by-line
F10 will continue with the next line of code.
F11 will attempt to drill down into what ever functions are on the current line of code
Ctrl-D will bring up a "Quick Watch" window giving you all information about the currently selected variable/object.
Once you are in debug mode there are tons of things you can do - in some cases you can even edit the code as you go.
The easiest way to get into debug mode is to use the little "play" button up at the top of visual studio - and when a break point is reached it will enter debug mode and highlight the currently executing line of code.
You can also hit F10 from the editor and your application will be started and paused on the very first line of code.
By comparison, in PHP, you had to actually write "debugging code" into your application - using Visual Studio you can actually monitor the execution of your code without adding a thing to your existing code.
I hope that gets you started.
You might want to also read up on your IDE a bit to. There is a metric ton of stuff in visual studio that will help you navigate your code in ways you never imagined in most PHP editors.
If you've already downloaded Microsoft Visual Studio, you'd might want to check out the Visual C# Express Library available for free over at: http://msdn.com/express/
It's located down the bottom of the page and is very useful. It contains pretty much every answer you might be looking for as a beginner to the C# Language. ...Welcome to C#, my friend :-D
So my C# program is quitting/disapearing/closing/crashing suddenly even in debug mode.
How can I make it break/pause/stop so as to find out where caused it?
Set a breakpoint (by clicking the left of the line numbers--it's a red circle) that you know is before the point where it crashes and then step through it (using F8). The last statement that you're on is the one that it's crashing at.
If you're in Visual Studio you can enable "Stop when an exception is thrown" - go Debug->Exceptions. This is often quite useful for detecting the exact source of the problem.
You may be able to learn more by using an unhandled exception handler. However, if you're in debug mode you should be able to see it by default. Check your Debug: Exceptions settings to make sure you haven't accidentally stopped reporting them in debug mode.
as Eric suggested try going through step through it... also always place try/catch in your end caller apps in order to manage exceptions.
Also, it may be worth checking your code for occurrences of Environment.FailFast, just in case someone tried to be (too) smart.
You can hit F10 to start debugging your project. This will put a breakpoint right at the beginning of your Main method, then you can go from there stepping through the code with F11 to see at which points it crashes.