Top Visual Studio Debugging Tips That Can Save You Hours!
Thu 9 June, 2016 / By Jon D Jones
We've all been there, annoyed, hours deep into an issue with no sign of solving it. In today's guide, I'm going to cover some of the most useful debugging tips I've stumbled across.
How To Render/Copy All Of An Object Values
This one is really simple but is really useful to quickly find the state of an object.
In the immediate window, type in '?[name_of_variable]'. In the immediate Window, you will now see a print out of everything in the object. You can manually copy it into notepad etc.. you can even use the immediate window's logging features to automatically write it to a file.
I'm hoping everyone knows how to set and get a breakpoint to hit. Did you know you can also set conditional breakpoints, so a breakpoint will only ever get trigger if some conditional criteria is met.
To set a condition breakpoint, set a normal breakpoint, right-click on it and select 'Condition'
The 'Breakpoint Settings' dialog should appear, as seen below:
The cool feature of the conditional breakpoint is that as soon as you type in the 'Condition' box, Intellisense will pop-up and help you find the variable you want to use. In here, simply add your condition logic that you want to trigger the break-point.
Quick Debug Attaching
I work with Sitecore a lot and I regularly need to attach my debugger to a website in IIS rather than Casini. TO speed up your development, you should download ReAttach, available from here
With ReAttach, the first time you debug you still need to connect as normal. After the first time, you can use ReAttach's dropdown to quickly connect to the debugging process you need. I genuinely love this plug-in!
Breakpoint Arn' Just Line Level!
This tip is useful if you want to debug inside a lambda expression. When I started using Visual Studio, I added my breakpoint to the left gutter and assumed that was all I could do. Visual Studio actually allows you to set break-points at a code level.
Inside a lambda expression for example, right-click on the part of the code you want to debug and choose 'Breakpoint' > 'Insert breakpoint'.