Debugging the InitializeComponent function in the Visual Studio designer

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Debugging the InitializeComponent function in the Visual Studio designer



In testing a number of changes to a custom WinForms control I'm encountering some issues which only occur when loading a form hosting the custom control in the Visual Studio designer.



As a result, I'd like to understand if there is any method for debugging and stepping through (or logging in some way) the behaviour of the custom control's code when the Visual Studio designer loads.





Well what's stopping you from just stepping into it as normal? I've just tried it and it seems fine.
– Jon Skeet
Feb 8 '14 at 21:54





I must be missing something obvious as the breakpoints in the custom control's code don't seem to be triggering when firing up the designer.
– Chris Cook
Feb 8 '14 at 22:13





Ah, sorry - misread the question. I stupidly didn't see the "in the designer" bit. Not sure why. Apologies again.
– Jon Skeet
Feb 8 '14 at 22:49




2 Answers
2



When debugging custom controls, you need to launch a second instance of Visual Studio by setting your project's debug properties to "start external program" and set the executable path to devenv.exe.



Then in the second instance of VS, open the project you're working on, and you will be able to debug the code triggered by the designer. In the 1st instance, set breakpoints in your custom control, and they will be hit when the 2nd instance calls up the Form.



Cheers





Many thanks - that did the trick. Whilst I've been developing custom controls since the early days of .net, it's the first time I've needed to debug them in this way. What slightly surprised me is that the designer doesn't appear to call the InitializeComponent function at all. Could you point me in the direction of any good resources covering the designer aspects of custom control development?
– Chris Cook
Feb 9 '14 at 12:43







My understanding is that InitializeComponent is parsed by the designer, but not executed. This is a good introduction: msdn.microsoft.com/en-us/magazine/cc164159.aspx
– Luc Morin
Feb 9 '14 at 19:28


InitializeComponent



VS2015: Under "Debug", "Options", "Debugging", "General" uncheck the "Enable just my Code".






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

'Series' object is not callable Error / Statsmodels illegal variable name