<p>Is there a good way to debug errors in the Visual Studio Designer?</p>

<p>In our project we have tons of UserControls and many complex forms. For the complex ones, the Designer often throws various exceptions which doesn't help much, and I was wondering if there's some nice way to figure out what has gone wrong.</p>

<p>The language is C#, and we're using Visual Studio 2005.</p>

[{'answer_id': 39671, 'author': 'Yaakov Ellis', 'author_id': 51, 'author_profile': 'https://Stackoverflow.com/users/51', 'pm_score': 0, 'selected': False, 'text': '<p>Each one is different and they can sometimes be obscure. As a first step, I would do the following: </p>\n\n<ul>\n<li>Use source control and save often. When a designer error occurs, get a list of all changes to the affected controls that have occurred recently and test each one until you find the culprit</li>\n<li>Be sure to check out the initialization routines of the controls involved. Very often these errors will occur because of some error or bad dependency that is called through the default constructor for a control (an error that may only manifest itself in VS)</li>\n</ul>\n'}, {'answer_id': 39677, 'author': 'ljs', 'author_id': 3394, 'author_profile': 'https://Stackoverflow.com/users/3394', 'pm_score': 1, 'selected': False, 'text': "<p>I have had this happen many times and it is a real pain.</p>\n\n<p>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.</p>\n\n<p>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.</p>\n\n<p>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.</p>\n\n<p>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.</p>\n\n<p>Basically as far as I can tell there's no real way around the problem other than to slog it out a bit!</p>\n"}, {'answer_id': 39791, 'author': 'Craig', 'author_id': 2047, 'author_profile': 'https://Stackoverflow.com/users/2047', 'pm_score': 5, 'selected': False, 'text': '<p>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".</p>\n\n<p>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.</p>\n'}, {'answer_id': 339784, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': True, 'text': '<p>See <em><a href="http://msdn.microsoft.com/en-us/library/ms996457.aspx" rel="nofollow noreferrer">Debugging Design-Time Controls</a></em> (MSDN).</p>\n'}, {'answer_id': 2845042, 'author': 'Kevin Phelps', 'author_id': 342528, 'author_profile': 'https://Stackoverflow.com/users/342528', 'pm_score': 0, 'selected': False, 'text': "<p>You can run a second instance of VS and attach it to the first instance of VS (Ctrl+Alt+P). In the first instance set the breakpoints, in the second instance run the designer, and the breakpoint will fire. You can step through the code, but Edit-and-Continue will not work.</p>\n\n<p>For Edit-and-Continue to work, set you control library's debug options to run a VS with the command line argument being the solution filename. Then you can simply set the breakpoints and  hit F5. It will debug just like user code! As a side note, you can do this will VS and Office add-ins also.</p>\n"}, {'answer_id': 23353120, 'author': 'ShawnFeatherly', 'author_id': 228738, 'author_profile': 'https://Stackoverflow.com/users/228738', 'pm_score': 1, 'selected': False, 'text': '<p>I discovered why sometimes breakpoints are not hit. In the <em>Attach to Process</em> dialog, "Attach to:" type has to be "Select..."\'d.</p>\n\n<p>Once I changed to "Managed 4.0, 4.5", breakpoints for a <a href="https://en.wikipedia.org/wiki/Windows_Runtime" rel="nofollow">WinRT</a> application were hit. Source: <em><a href="http://www.codeproject.com/Tips/590634/Designer-Debugging-in-WinRT" rel="nofollow">Designer Debugging in WinRT</a></em>.</p>\n'}, {'answer_id': 38348884, 'author': 'Haymo Kutschbach', 'author_id': 1215993, 'author_profile': 'https://Stackoverflow.com/users/1215993', 'pm_score': 2, 'selected': False, 'text': '<p>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 <code>Debugger.Break()</code>. You may wrap it into a compiler conditional as so:</p>\n\n<pre><code>#if DEBUG\n   System.Diagnostics.Debugger.Break(); \n#endif\nint line_to = break; // &lt;- if a simple breakpoint here does not suffice\n</code></pre>\n'}, {'answer_id': 72112495, 'author': 'Cosmin', 'author_id': 626533, 'author_profile': 'https://Stackoverflow.com/users/626533', 'pm_score': 0, 'selected': False, 'text': '<p>This worked for me for Visual Studio 2022:</p>\n<ul>\n<li>I opened a second Visual Studio instance</li>\n<li>In the second instance I clicked <em>Debug -&gt; Attach to Process...</em></li>\n<li>I selected <em>DesignToolsServer</em> from the process list</li>\n</ul>\n<p>More details: <a href="https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/walkthrough-debugging-custom-windows-forms-controls-at-design-time?view=netframeworkdesktop-4.8" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/walkthrough-debugging-custom-windows-forms-controls-at-design-time?view=netframeworkdesktop-4.8</a></p>\n'}]
['https://Stackoverflow.com/questions/39648', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4037/']