How to cope with designer errors in Visual Studio
From time to time, when you have some errors in your controls, Visual may just stop responding altogether and forces you to restart without any indicator on what happened and how to fix it. To overcome this, there is two things developers should keep in mind:
- Check database and connection routines, make sure they are initialized properly or blocked from running by checking the special property DesignMode (available as Form.DesignMode and UserControl.DesignMode).
- To see the cause of the error, you have to debug Visual Studio itself. When designer error happened to you, choose debug this program and start a new instance of Visual Studio. The second instance should give you the unhandled exception and the code location of the error.
I think this is an artifact from the first days of Visual Studio carried over when they expect all code to behave (after all, developers have to spend years just for planning and resources is not available as much as today). For this Microsoft are way behind Eclipse: In android development tools, if you have errors in your control, the designer at least give you a message about the error and refuses to continue rendering the screen but it won’t crash. Visual Studio, on the other hand, requires a full restart which consumes a lot of time (this particular time it took me 2 hours to find the source of the error).