Productivity Power Tools for VS 2017

Productivity Power Tools is nothing new, many developers are well aware of it and use it for long time. I am certainly among one of them. However, every now and then I come across seasoned developers on Microsoft platform with years of Visual Studio experience who are doing things in old-fashioned way while more efficient mechanisms available such as  Productivity Tools.

With Visual Studio 2017, the tradition for these Productivity Power Tools continue. You can download and download and install it from within Visual Studio 2017. In case you haven’t done it before, simply go the “Extensions and Updates” menu options under Tools as shown below.

1

At this point, simply search for Productivity Power Tools 2017. Once you find it, simply download and install it.2

A full list of available tasks with these tools is available at its page at Visual Studio marketplace as well as its github page.

Being a keyboard junkie, my personal favourite from Productivity Power Tools is QuickTasks which provides quick access to common tasks via the Quick Launch bar. Just as a reminder, you can find the Quick Launch Bar at the top right corner of Visual Stuio as shown below.

3

These quick tasks are available by @tasks shortcut.

4

Below is some tasks that could be performed.

5

A full list of QuickTasks is available here.

Until next, happy debugging.

Posted in Visual Studio 2017 | Leave a comment

Creating Process Dump file from Visual Studio

Dump file based troubleshooting and debugging approaches provide effective ways of understanding certain type of issues. I have written tutorial on this subject to little advanced techniques. When it comes to collecting dump file for a process, I am big fan of tools such as ProcDump and DebugDiag.

I think not many people realize that a process dump file can also be collected from Visual Studio. If you are working from developer’s favourite tool “Visual Studio”, its entirely possible to collect dump file of a target process during debugging without leaving the comfort of Visual Studio. This can be achieved when you are debugging a program. At that point, a menu option of “Save Dump As” becomes available under Debug menu option as shown below.

If user chooses this option, user is prompted to choose the name and location of that dump file as shown below.

Until next, happy debugging!!

Posted in Debugging | Leave a comment

Visual Studio 2017 – Exception Helper (III)

Exception Settings has been a powerful feature in Visual Studio for quite some time now. It has got some extra fire-power with new Exception Helper dialog in Visual Studio 2017. Let’s say, your code is using a third party library that is throwing an exception.Let’s also say  that this exception is of no much interest to you when its raised by that third party library. Otherwise you would like your debugger to break every time that same exception is thrown. Let me show how you can accomplish this with Visual Studio 2017.

Let’s say your solution has a dependency on a third party library for Video Streaming.

0

When using this library, its throwing an exception that’s interfering your debugging experience. In general, you would like your debugger to break on the exception, however, you don’t want the same behaviour when exception is thrown from this VideoStreaming library. With Visual Studio 2017, you can set a condition for this Exception to break except when its thrown from VideoStreaming.dll as shown in the image below.

1

If this check-box for VideoStreaming.dll is checked, it will add a condition in the Exception Settings for this particular type of exception as shown below.

2

In case you decide to remove this setting, just right click on this condition will bring up follow context-menu.

3

Select “Edit Conditions” here, which will bring following pop-up. This dialog provides you ability to either modify the condition or remove it entirely.

4

Until next, happy debugging.

Posted in CodeProject, Visual Studio 2017 | Leave a comment

Visual Studio 2017 – Exception Helper (II)

Another time saving feature in the new Exception Helper dialog in Visual Studio 2017 is about Inner exceptions. In order to elaborate this, let me first introduce you to what happens when an unhandled exception is encountered when debugging code within Visual Studio 2015 (or earlier version). You basically are presented with a dialog showing the type of exception but without why the exception was thrown as shown in image below.
1

Of course, there is a link for View Detail that can help you getting more details about that exception. However, some times the actual exception is buried deep inside nested Inner Exception as in the example shown below.

2

The same scenario in Visual Studio 2017 Exception Helper dialog is presented in following manner. Here you can see that there are three inner exception with the inner most one shown at first.

3

Of course, you can inspect the other two exceptions in this case by left and right navigation arrows as shown in images below.

4

5

Until next, happy debugging!!

Posted in CodeProject, Visual Studio 2017 | Leave a comment

Visual Studio 2017 – Exception Helper

Exceptions is an ancient programming concept that every developer has to deal with in the programs they write during development, testing and production scenarios. Visual Studio has long provided facilities to inspect the exceptions but with Visual Studio 2017, its Exception Helper dialog makes that process even easier.

In order to set the stage, let’s look at the following piece of code, specially the line shown in red rectangle below.

1

As you can see, there are various properties invoked for different objects on this line without ensuring that these objects are not null. This type of code can cause tricky situations to deal with specially in a production environment as I described in one of my article for Visual Studio Magazine.

Let’s say, when debugging this application in Visual Studio 2015, an exception is thrown on the same line of code. In this case, Visual Studio 2015 will display following dialog.

2

Its showing that a NullReferenceException has been caused on the same line but without much details about which object is responsible for the exception. Clicking on View Detail here brings up following dialog.

3

This dialog is also not telling us either about the object causing the exception. Obviously if you are debugging this code, you can inspect all related objects to determine the culprit but this is exactly where Visual Studio 2017 Exception Helper can save some of that time.

Same program when debugged under Visual Studio 2017 presents following dialog.

4.PNG

As you can see in this case, Visual Studio 2017 is clearly showing that its the product.Detail object that returning a null causing the exception. Isn’t it great and a time saver?

There are many other tit-bits that you can do with this Exception Helper in Visual Studio 2017 that I will continue to explore in my upcoming blog posts.

Until next, happy debugging!!

Posted in CodeProject, Visual Studio 2017 | Leave a comment

Visual Studio 2017 – Run To Click

Visual Studio 2017 has provided several key improvements in Debugging experience. One of them is called “Run To Click”. “Run to cursor” has been a familiar experience for all developers for many years. This provided a convenient way of running your program to the cursor location using a short-cut such as Ctrl+F10. Of course, same could also be achieved by adding a break-point on the line of code and hitting F5. Of course adding a break-point meant that your program execution could be stopped at the same line again. However both of these approaches have their own “latencies” that Visual Studio team decided to address in Visual Studio 2017. Let’s say your are debugging your program, during that you may notice green Glyph appearing as shown in red rectangle in picture below.

1

Hovering the cursor on the glyph shows “Run execution to here” tooltip as shown below.

1a

If you click on the glyph here, the program execution will continue and stop at this line. In this example, user will be first prompted to enter the length of Fibonacci series. Let’s say user enter a number 5 here.

2

Once user hit enter key, the execution will stop on the same line.

3

That’s great. It certainly saves some time when debugging. But wait, things can be even better. From the code, we can see that the GenerateFibonacciSeries method will be called next within the if statement. Let’s say I want to debug the loop within that method. All I need to do is to take my mouse to that line and you will see same green glyph there as shown below.

4

Just as the name of feature says, you just “Run to Click” and it will take you right there.

5

As you can see from the Local window, the program execution stopped at the first iteration in the loop. If needed, you can click on the green glyph again on same line and execution will stop on the second iteration of same loop.

6

Until next, happy debugging!!

Posted in CodeProject, Visual Studio 2017 | Leave a comment

C# 7.0 – Deconstruct in a C# Class

In my blog, I explained how a Tuple could be consumed via deconstruction. Its important to know that this concept is not specific to Tuples. In today’s post I will show how that concept could be applied to a regular class.  Let’s say you have following Employee class.

class Employee
{
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public string MiddleName { get; set; }
}

You can add a Deconstruct method to this class that accepts out parameters that could be initialised in the method for consumption by deconstruction. So let’s add a Deconstruct method as follows.

class Employee
{
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public string MiddleName { get; set; }

  public void Deconstruct(out string firstName, out string lastName)
  {
     firstName = this.FirstName;
     lastName = this.LastName;
  }
}

Now this class can be consumed as follows using deconstruct syntax.

static void Main(string[] args)
{
    var employee = new Employee() { FirstName = "John", LastName = "Doe", MiddleName = "Sue" };
 
    (string firstName, string lastName) = employee;
    Console.WriteLine($"First Name = {firstName} Last Name = {lastName}");
}

Output of this will be as follows.

Capture

Your class can expose more then one Deconstruct method with varying number of parameters, so that it can be consumed appropriately.  Code below shows same Employee class with two Deconstruct methods.

class Employee
{
 public string FirstName { get; set; }
 public string LastName { get; set; }
 public string MiddleName { get; set; }

 public void Deconstruct(out string firstName, out string lastName)
 {
    firstName = this.FirstName;
    lastName = this.LastName;
 }
 public void Deconstruct(out string firstName, out string lastName, out string middleName)
 {
    firstName = this.FirstName;
    lastName = this.LastName;
    middleName = this.MiddleName;
 }
}

Now you can consume the object using deconstruction in similar manner as shown below.

static void Main(string[] args)
{
  var employee = new Employee() { FirstName = "John", LastName = "Doe", MiddleName = "Sue" };
 
  (string firstName, string lastName, string middleName) = employee;
  Console.WriteLine($"First Name = {firstName} Last Name = {lastName} Middle Name = {middleName}");
}

The output now contains the Middle Name as well.

Capture

Until next, happy debugging.

 

Posted in Uncategorized | Leave a comment