C# Step Into variable list - c#

There usually is a variable list at the bottom of the screen that helps me follow the value of different variables in my app while using the f11 'step into' function, but since I updated to web developer 2012 I can't seem to find this list. Was it removed? or is there a way to open it? thanks!

Set a break point in the project, start debugging your application, once you hit the break point, go to Visual web developer, Under Deubg-> Windows, see if you find Locals option. That will show the local variables during debugging.

Related

Visual Studio 2013 stopped showing variable values when debugging

In a particular project I recently started the debugger started acting funny. When I'm debugging and it is paused at a breakpoint, Data Tips don't show up, some of the variable values don't show up in the Locals and Autos windows, and there are some strangely named variables in the Locals window (the ones starting with "CS". The other ones are my variables):
I can't for the life of me figure out what is different about this project than my other ones. I'm running Visual Studio 2013 in Windows 8.1. The project is a Windows Phone 8 project, with the only added references being Fody, PropertyChanged.Fody, HttpClient et alius, and JSON.net.
Any help would be appreciated.
I had the same problem here (also using windows 8.1 and VS 2013)
To fix it you need to open in VS Tools | Options | Debugger | General and enable the flag [Use Managed Compatibility Mode], which essentially gives you the VS 2012 function evaluation behavior.
Reference:
http://weblog.west-wind.com/posts/2013/Nov/21/Visual-Studio-2013-Could-not-evaluate-Expression-Debugger-Abnormality
[Build] => [Clean solution] has fixed this issue for me when nothing else has worked including emptying the symbol cache.
Try TOOLS->OPTIONS->DEBUGGING->SYMBOLS and hit button Empty Symbol Cache.
This did the trick for me (VS 15 on WIN 10):
Debug --> Options --> On General tab check Use legacy C# and VB expression evaluators.
I tried above all suggestions but none of them worked for me. Following resolved my issue -You can try by resetting VS settings. Tools-> Import and Export Settings -> Reset All Settings and then press Next.
If you're referring to the 'locals', you can reopen it (while debugging) by going into Debugging -> Windows
It's only accessible during a debugging session.
I was facing some weird issue on my Visual Studio 2017 (Community) installation while debugging which is how I reached this thread. I'm posting my findings in case it helps someone. Any of the already posted answer's didn't help me.
The thing was whenever I hover my mouse over a variable during a debugging session then I can see its value in tool tip but it was working only for primitive data types e.g. int, char, string etc. In case the target variable was an object or an array I will not see any way to expand the object to see its property values, internal members and things like that as shown in the screenshot below for variable A which is an array:
So to overcome this problem for non-primitive data type variables (objects and arrays), every time I will select the variable and press Ctrl + F9 to open the quick watch window and see the object members there but gradually it was becoming irritating and time consuming.
While trying various solutions present in this thread by mistake I clicked on the empty area beside the variable name in the tool tip window and whoaaa it was all there :)
In general in that empty area on the left hand side of the tool tip window, there is a plus (+) sign which we click to expand the object details but it was just that the plus (+) sign was invisible. I reverted all the options I had applied as per the suggestions mentioned in this thread and it was still working.
So I concluded it was just a curious case of invisible plus sign. Now I've a normal debugging life :P
Root cause of the problem could be Visual Studio 2017 Community (Version 15.3.0) or Windows 7 which is my host operating system(OS). As far as display drivers are concerned then that's not the case for sure as I had built this laptop more than a year back and it had been all good for all other applications.

Is it possible to add a watch to a variable without being in Debug mode?

I was just trying to add a watch to one of my class fields before starting to Debug but could not find the menu items anywhere. I know that I can add them once I start debugging, but is there a reason why the menu items are not available before starting to debug?
http://msdn.microsoft.com/en-us/library/0taedcee%28v=vs.100%29.aspx explains that the Watch and Quick Watch windows / views are only available during a debugging session.
One thing I do, however, to quickly evaluate / check on variables in Ctrl+D, Q, which is the shortcut for the Quick Watch window. This allows me to type in C# expressions and see what they resolve to.

Getting debugger context in C# interactive

C# Interactive seems a lot more powerful than the Immediate Window (at least it handles lambda expressions that are often used in LINQ - see Visual Studio debugging "quick watch" tool and lambda expressions), but it looks like it can't be used as a replacement as it doesn't know about the debugger context. Is there a way to have access to the debugger context?
I've seen Getting debugger context in F# interactive and it might require the same things, but maybe there are new/different things available.
http://extendedimmediatewin.codeplex.com/ could be useful but looks quite dead, although someone said on Oct 18 2011 that he was planning to port it to VB.Net ( http://extendedimmediatewin.codeplex.com/discussions/75589 ).
Not a complete solution, but in VS2015, after you've run Initialize Interactive with Project, you can use Debug > Attach to Process to connect to the InteractiveHost.exe process.
You can then debug functions from your project. You won't be able to debug one-off functions in the Interactive window, though, as Kevin explained.
As as side note, https://stackoverflow.com/a/40650343/467110 points out that you may have to have a C# Interactive window open before you open your solution in order to successfully Initialize Interactive with Project
Disclaimer: I work for Microsoft on the Roslyn team.
Unfortunately, we don't have a way to get the debugger context right now. We are aware that it would useful, and as we get more of the core deliverables for Roslyn completed we hope to investigate more and see what can be done.
Inside C# Interactive you can run
System.Diagnostics.Debugger.Launch();
to request a debuger, whereby you will get a window asking you to choose one of the open Visual Studio instances or a new instance to attach. Assuming you used "Load Interactive with the Project" option of Visual Studio - any breakpoints in the open Solution will now be hit when code is ran by Interactive.
If you need the debugger without pre-existing code - you can now insert
System.Diagnostics.Debugger.Debug();
calls into the code you put into Interactive (but it does have to go in one 'chunk', i.e. one press of 'enter'), and you will be able to examine local vars via 'locals' window and run code against interactive context via 'immediate' window.

Debugging Silverlight in Visual Studio 2010

I have an MVC application which uses a silverlight control.
Somewhere along the line something is happening in the silverlight cs code that isn't right. I've inserted break points in the CS silverlight code to get a better idea of what's happening, but for some reason I just can't step through the code.
I know code is being hit, but it's just not showing me in the debugger.
I thought it might be because I was using Chrome as the default browser but I changed this to Internet Explorer and still no joy.
I realize this is a very vague question, but has anyone else experience anything similar, and if so, how did you get around it?
Any help would be appreciated,
Thanks.
Be sure to set the Silverlight Debugging checkbox on the project properties Web tab
If Chrome is your default browser and your breakpoint tooltip shows this message:
"The breakpoint will not currently be hit. No symbols have been loaded for this document"
... then it is possible the debugger attached to the wrong Chrome process at debug startup. A work-around is:
Start debugging your Silverlight app. Your app should be running in Chrome.
From the Debug menu, select Attach to Process...
Scroll through the available processes and locate the chrome.exe process that shows the type as 'Silverlight x86'.
Select that process and click Attach.
I had firefox as my default browser and nothing was being hit(I even tried attaching to a process). What finally worked for me was setting IE as the default.
Silverlight break points are now being hit for me! :)
Right Click on Web.UI project in solution. go to Web , check Debuggers --> Silverlight save and Debug..
Make sure you have silverlight developer installed.
Your code may be part of a class marked with the System.Diagnostics.DebuggerStepThroughAttribute. This happens with auto generated classes (like with Add Service Reference). If you are extending a partial class, other parts of the class definition may have that attribute.
Try unckecking the Options / Debugging / General / Enable Just My Code checkbox.
Otherwise put your mouse over the red dot in the source code window, which becomes an empty circle if the debugger disabled it, a tooltip will give you additional information.

Debugging C# applications

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

Categories