I frequently use Debug -> Exceptions -> check CLR Exceptions during debugging sessions. Sometimes, an exception gets thrown and handled, but I really want to find the source of the exception. In order to do this without seeing first-chance exceptions that I don't care about, I start my app, and then check CLR Exceptions:
This gets really tedious, and I'd love to have a toggle button in my VS2010 toolbar that allows me to only set/reset CLR Exceptions at will, without having to key in CTRL+D, E, check the box, and then click OK (and then do the same process again to turn off the exceptions). I went into the toolbar customization, but all I could get was a button that bring up the Exceptions dialog. This is obviously less efficient than hitting CTRL+D, E.
Does anyone know of another way to add this? Will it require a VS addin? A keystroke mapping would be nice as well.
I've never used the Macro Recorder in VS ever, but maybe this is one place where it's necessary?
Yes.
Use the macro recorder to record the steps.
Rename the macro to something mnemonic.
go to (tools)(customize)
at the bottom there is a keyboard button you can use to map that macro to a key or
the commands tab will allow you to (add command) to any specific menu or tool bar.
Related
I'm working on a project in Silverlight and somewhere an exception is thrown. I'm not concerned with fixing the exception... I just want to find it.
Instead of Visual Studio popping up and showing the the line where the exception happened, I instead get a little window labeled "Just In Time" which mentions an error 4004, a managed runtime error. It asks which debugger I want to use to solve the problem. But, it only provides one option: a new instance of Visual Studio. If I try to accept its proposal, the new instance complains that a debugger is already attached.
Why doesn't the instance of VS which built the program and is already running catch the exception and show me where it is?
That is strange behavior. The first thing I would do is change a few settings
Disable Just My Code
Enable native debugging
Break on first exception thrown
This should help you narrow down the place where the exception is occuring.
Disable Just My Code
Tools -> Options
Debugger
Uncheck "Enable Just My Code"
Enable Native Debugging
Right click on the project and select properties
Go to the Debug Tab
Check "Enable Unmanaged Debugging"
Break on first exception thrown
Debug -> Exceptions
Check "Throws" for Common Language Runtime Exceptions
Silverlight has a habbit of swallowing exceptions. I call this "silent failure" and have found it very expensive and frustrating. When working with Silverlight do everything you can do expose exceptions, e.g. binding failures.
Have a look here: http://msdn.microsoft.com/en-us/library/cc189070%28v=vs.95%29.aspx
Also there is a setting on elements to have them visualise binding failures but I forget what it is as I'm not working in Silverlight any more.
Looks like the problem is the type of debugging. In your project properties make sure you enable Silverlight debugging. In your website project right click, go to properties, then on the 'Web' tab at the bottom there's a section called Debuggers. Make sure that Silverlight is selected.
Sometimes the JS debugger is attached to the IE process, which means that there's a debugger attached, but it's simply not the debugger you want. I think this might be the cause of this problem.
Hope this helps.
Miguel
click debug, choose exceptions, mark common language runtime exceptions as thrown.
I had the same problem and it fixed the problem for me
1) I put a breakpoint, VS breaks where I put the breakpoint.
2) I then start browsing around the code normally to put another breakpoint
somewhere down the execution path. (maybe in another class in some other cs file)
3) I would now like to return to where I first stopped (just navigation in the code. Do not confuse with the go back in debugger feature used in VS's intellitrace debugging tool)
Right now I place a bookmark and return to my bookmark. But I forget most of times to place a bookmark. Hence this question. There's got to be a shortcut to get back to current line of execution or stopped at or whatever phrase is used to describe this. I also have Resharper if I can craft up some hotkey or shortcut. Anyway I can get back to where the debugger has "broken". I sometimes also use Ctrl - multiple times to navigate backwards.
thank you
That would be the Visual Studio command "Debug.ShowNextStatement" (usually assigned to Alt+Num*). You can also use the Breakpoints Window (Alt+Ctrl+B) to navigate between your breakpoints.
UPDATE: I implemented #Alex 's request for a more discoverable and accessible MenuItem for this functionality, as part of a commercial Visual Studio extension I created called OzCode. It works similarly to Resharper's Context Actions: when you are in break mode but have navigated far away from the 'current statement', this QuickAction will appear:
I tend to use the call stack window, double click the top line in the stack trace causes the editor window to display the code line where execution halted
I would like Visual Studio not to enter the Debug mode when it picks up a specific exception I define (i.e. BusinessException is this case). This is because I have a specific global error handler that will then present this to the user.
Is there a way to avoid the VS debug pickup for this exception (so I'll go straight to seeing my exception handler dialog) but for other exceptions to still be handed by the VS debugging.
I'm using VS2008 for a C# project (winforms).
thanks
EDIT: Further clarification - currently I see (a) VS pick them up and show them in the debugger, and after I hit continue I see (b) them in my custom exception handler. What I want to do is disable step (a) for certain types of exceptions. I know that I can disable totally in VS by going to the settings and uncheck "Enable just my code", however that's not quite what I want.
May be you can try DEBUG Preprocessor
http://www.csharphelp.com/2005/12/c-languages-preprocessor-directives/
Is there a shortcut to cycle through my breakpoints? I often lose track of the breakpoints when debugging a project. When I finish working with one bug, I have to reset my breakpoints for a new bug that I am about to solve. It would be handy to have a keystroke that would allow me to cycle through the breakpoints and disable ones I don't need and keep the ones I need.
You can always open the breakpoints window (Ctrl + Alt + B) to cycle through them.
I don't believe you can.
You can display a list of all breakpoints and jump to them using the breakpoint view (Debug / Windows / Breakpoints).
You may also be able to write a macro to do it if you want.
I don't think there is a built in way of doing this. However you might want to take a look at this question. You can probably save the breakpoints for one bug and load it whenever you want it.
Is there a good way to debug errors in the Visual Studio Designer?
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.
The language is C#, and we're using Visual Studio 2005.
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.
Each one is different and they can sometimes be obscure. As a first step, I would do the following:
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
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)
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.
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.
This worked for me for Visual Studio 2022:
I opened a second Visual Studio instance
In the second instance I clicked Debug -> Attach to Process...
I selected DesignToolsServer from the process list
More details: https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/walkthrough-debugging-custom-windows-forms-controls-at-design-time?view=netframeworkdesktop-4.8