Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to troubleshoot and debug Visual Studio design mode errors?

Using Windows 7 and Visual Studio 2010, I am writing a C# custom UserControl. I was coding in code view for weeks and recently when I tried to switch to design mode, Visual Studio hanged, "NOT RESPONDING". I can wait for an hour, and still nothing happens. Clicking on the close button it gives the "Do you want to wait, close, restart and send information to Microsoft" dialog.

Is there a way to (stack)trace the code that the designer is trying to execute? Maybe design-time trace messages or breakpoints?

like image 902
Jake Avatar asked Dec 04 '12 07:12

Jake


People also ask

How do I fix breakpoint in Visual Studio?

Hover over the breakpoint symbol, choose the Settings icon, and then select Remove breakpoint once hit in the Breakpoint Settings window.

How do I fix unhandled exception in Visual Studio?

To change this setting for a particular exception, select the exception, right-click to show the shortcut menu, and select Continue When Unhandled in User Code. You may also change the setting for an entire category of exceptions, such as the entire Common Language Runtime exceptions).


3 Answers

For Visual Studio 2010, this answer does the job.

For Visual Studio 2012 or above, what you need to do is actually debug the Visual Studio Designer process. The process you want to debug is called XDesProc.exe

Enter image description here.

I do the following:

  • Open two instances of Visual Studio both pointing to the same solution
  • Close all windows in both.
  • Kill all XDesProc.exe instances in Task Manager
  • In Visual studio instance A, open any view (not one that has the exception). This will start the XDesProc designer process for Visual Studio Instance A
  • In Visual Studio instance B, attach to process on XDesProc.exe and set your breakpoints, or, set Break on exceptions
  • In Visual Studio instance A, open the view (that has the exception)
  • Visual Studio B should break.

Enter image description here

If you missed it, or need to restart the steps, start again from step (2) 'Close all windows' killing XDesProc instances. Sometimes the designer starts up once and caches values, and you will need to have a clean, non-exception designer to track down the problem.

like image 140
Dr. Andrew Burnett-Thompson Avatar answered Oct 04 '22 08:10

Dr. Andrew Burnett-Thompson


For Visual Studio 2010/2013

You can debug the Visual Studio designer itself! Open a second instance of Visual Studio, use the Tools -> Attach To Process and attach to the first Visual Studio (i.e. devenv.exe).

In Visual Studio instance #2 (the one that you did the Attach To Process in): Put a breakpoint on your usercontrol's constructor

In Visual Studio instance #1 (the original one, that will get stuck): Open the designer which your usercontrol is in, the breakpoint in VS#2 will get hit.

For Visual Studio 2012

The process you want to debug is XDesProc.exe - see Dr. ABT's answer. Otherwise the procedure is as for Visual Studio 2010/2013.

like image 20
Blachshma Avatar answered Oct 04 '22 08:10

Blachshma


The answer is in Walkthrough: Debugging Custom Windows Forms Controls at Design Time (MSDN).

like image 41
fernaramburu Avatar answered Oct 04 '22 09:10

fernaramburu