Today I will try to describe the technique used rarely to find bugs. It involves the use of second instance Visual Studio to find errors in the first. Looking at the last sentence, you can begin to think about how to look for errors in Visual Studio can help you find bugs in our program. It should be realized, that really Visual Studio incorporates our code. And our goal is to trace the activities of this code.

Prime example of this technique is to repair windows or controls, who do not want to appear correctly in the editor. In such a situation usually get information, that there is an exception. Very often, people with more experience are able to determine on the basis of the information likely to place the error. There are also situations, when a bug causes the appearance of several / several exceptions. What’s more show exceptions may not apply to the source of the problem. Such a scenario is an ideal spot application techniques described.

Let’s start with … Below is a picture of the situation, in which it can not be displayed in the control Visual Studio.

Visual Studio Designer Error

As can be seen not managed to create an instance of the controls BasicPasswordGenerator and AdvancePasswordGenerator. Additional information is, that this error is caused by IsolateStorageException. If anyone has met previously with such a situation it is almost certain, that light can not be correctly displayed in one place because trying to read some values ​​from the IsolateStorage. Reading this only possible for furnishing, or emulator. If you try to execute it in Visual Studio we get an exception.

But if someone does not know where the error occurs it may cause a second instance of use Visual Studio. In the second instance, open the same project, in which there is a mistake and hook to the process of first instance Visual Studio (Debug -> Attatch to process…). Add to guide, the process Visual Studio is called devenv.exe. Now we choose the mode of action:

  1. Breakpoint in place of the suspect – standard approach for finding bugs. Try to identify suspicious places and try to trace the operation code. Most search begins with the designer controls.
  2. Permit the detection of space in which there is an exception by Visual Studio. Because this exception is handled is to modify the settings, that Visual Studio stopped at the site of the exception also handled. We do this by selecting Break when an exception is -> Common Language Runtime Exceptions -> Thrown in the Exceptions (menu Debug -> Exceptions…).

Visual Studio 2010 Debug View

After selecting the mode of action remains for us now only run in the editor control, which operates niepoprawiane and look where the error occurs.

Let’s start with … Below is a picture of the situation, in which it can not be displayed in the control Visual Studio.