Top Visual Studio Debugging Tips That Can Save You Hours!

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.

debugging_immediat_window

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.

Conditional Breakpoints

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’

debugging_conditional_breakpoint

The ‘Breakpoint Settings’ dialog should appear, as seen below:

debugging_conditional_breakpoint_1

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.

debugging_conditional_breakpoint_2

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’.

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

More Posts

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *