Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good Way to Debug Visual Studio Designer Errors

I've been able to debug some control designer issues by running a second instance of VS, then from your first VS instance do a "Debug -> Attach to Process" and pick "devenv".

The first VS instance is where you'll set your breakpoints. Use the second instance to load up the designer to cause the "designer" code to run.


See Debugging Design-Time Controls (MSDN).


It has been a pain in 2005 and still is in 2015. Breakpoints will often not hit, probably because of the assemblies being shadow copied or something by the designer(?). The best you can do is to break manually by introducing a call to Debugger.Break(). You may wrap it into a compiler conditional as so:

#if DEBUG
   System.Diagnostics.Debugger.Break(); 
#endif
int line_to = break; // <- if a simple breakpoint here does not suffice

I have had this happen many times and it is a real pain.

Firstly I'd suggest attempting to follow the stack trace provided by the designer, though I found that often simply lists a bunch of internals stuff that isn't much use.

If that doesn't work then try compiling and determining the exception from there. You really are flying blind which is the problem. You could then try simply running the code and seeing what exception is raised when you run it, that should give you some more information.

A last-gasp approach could be to remove all the non-generated code from the form and gradually re-introduce it to determine the error.

If you're using custom controls you could manually remove the generated code related to the custom controls as well if the previous method still results in an error. You could then re-introduce this step-by-step in the same way to determine which custom control is causing the problem, then go and debug that separately.

Basically as far as I can tell there's no real way around the problem other than to slog it out a bit!


I discovered why sometimes breakpoints are not hit. In the Attach to Process dialog, "Attach to:" type has to be "Select..."'d.

Once I changed to "Managed 4.0, 4.5", breakpoints for a WinRT application were hit. Source: Designer Debugging in WinRT.