15

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jake
  • 11,273
  • 21
  • 90
  • 147

3 Answers3

24

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.

Community
  • 1
  • 1
Dr. Andrew Burnett-Thompson
  • 20,980
  • 8
  • 88
  • 178
  • Hey! I'm using VS2013 and I don't see the XDesProc process, perhaos it's different? Also if I attach the debugger to the devenv process I don't get my checkpoints hit. Any ideas? – cgledezma Sep 29 '14 at 23:34
  • 3
    Nevermind. I had a small missconfiguration. And on VS2013 you actually attach to the devenv process BTW. – cgledezma Sep 29 '14 at 23:40
  • Visual studio menu -> Debug -> Exceptions. Check 'Thrown' next to 'Common Language Runtime Exceptions' :) – Dr. Andrew Burnett-Thompson Jul 21 '15 at 21:38
  • 1
    most important step : "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" The important point being you must have an XDesProc to attach to and there won't be one unless you open a xaml design view which doesn't throw an exception – Simon_Weaver Jan 16 '17 at 03:06
  • You also need to ensure that in the "Attach to Process" window you have selected "Managed (v4.*, v4.*)" code type in "Attach to" field. Also you need to open the Debug menu, select Exceptions and check the checkbox for Common Language Runtime Exceptions. You might want to uncheck all other types of exceptions in this window to not distract you. See for more info (with screenshots): https://blog.jayway.com/2013/12/25/visual-studio-2013-and-blend-design-time-exception-debugging/ – Artemious Feb 17 '17 at 17:24
16

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.

Community
  • 1
  • 1
Blachshma
  • 17,097
  • 4
  • 58
  • 72
  • Actually works! Except, somehow it doens't hit the breakpoints. I had to go to the VS #2 > Debug > Break All while VS #1 is in "not responding" state. – Jake Dec 04 '12 at 08:20
  • Make sure you have the same version of the usercontrol (dlls/pdbs) in both VS. – Blachshma Dec 04 '12 at 08:21
  • Ok so I have this problem: http://stackoverflow.com/questions/34664/designmode-with-controls – Jake Dec 04 '12 at 08:41
2

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
fernaramburu
  • 151
  • 1
  • 8