Visual Studio F5 and Ctrl+F5? - visual-studio-2010

I have strange problem here. I am using Visual Studio 2010. When I debug my code using F5, I am getting error. But without debugging (Ctrl+F5) code runs fine. So can anyone tell me what is the problem, what is the difference between both of them and how to overcome the problem?

I guess (cause you are no giving that much details) when you are talking about erros you are probably talking about exceptions right ?
The fact is when you are running your project with CTRL+F5 you are running WITHOUT debugging, and F5 "debugging".
So if you are facing exceptions while "debugging" and not while "not debugging" it seems to mean that those exceptions are properly catched. One way to get rid of those exceptions is to check within the Debug Menu / then Exceptions and to check that all "Thrown" checkboxes are unchecked. This Exception window is there to force debug process to break in case of Exception even if they are properly catched.
Hope this helps.

Related

Debugging drops out at the point of an error (Visual Studio)

I've been messing about a bit to try and get my debugger (VS2010) to allow me to step into the framework source code. (msdn) This didn't work and I ran out of time so changed my settings back, and now I don't get dropped into the debugger when a web project (in debug mode) throws an error, I simply get the yellow screen of death.
What's strange is that I can put a breakpoint in my code which works fine, and I can step over my code but as soon as I hit the line causing the error it drops out of the debugger back to the error in the browser.
I'm sure I've just got a setting wrong somewhere but its incredibly frustrating!
A colleague saved me! This article about Break when exception unhandled had the solution, I had the "Enable just my code" unchecked in Tools > Options > Debugging. No idea how it happened, but fixed now!

Silverlight Won't Show Exceptions

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

The breakpoint will not currently be hit. No symbols have been loaded for this document

I am dealing with a puzzling situation here,and need any help I can get . I am using Visual Studio 2008 and have a dev site running on IIS. When I Attach to the process running in IIS, it attaches successfully(no errors). However when I attempt to debug, nothing happens. I have closed out my browser, done a restart on the application pool, and website, cleared cache, and even forced a rebuild in visual studio. Still I am unable to step into code. Any idea what I could have wrong here?
The breakpoint will not currently be hit. No symbols have been loaded for this document.
Your symbols might be wrong or missing. In extra rare circumstances you might need to step inside the function via assembly, only then VS picks up that you're actually calling your component.
Check if you have you set compilation debug=”true” in you web.config file?
I believe you need to debug the website from within Visual Studio in order for breakpoints to be hit. Use the green "play" button, or use F5, or just go to Debug > Start Debugging.

Why doesn't Visual Studio 2010 break on an unhandled exception?

When there is an exception thrown in my program, and it is unhandled, I expect the debugger to break in my program and show me what the problem is. This doesn't happen. Instead, my program simply exits, and debugging stops.
If I look at the debugging output, I can see my exception:
A first chance exception of type
'System.NullReferenceException'
occurred in System.dll
I am using Visual Studio 2010, Visual Basic, writing a simple WinForms app. The code doesn't matter in this case... it happens with any exception that I've seen so far.
I've read a lot online about doing to the Debug menu and clicking Exceptions and enabling "break on unhandled user exception", but I don't see this option. I think this advice is for VS2008, and is no longer applicable.
I should also note that I'm not running any unit tests. I have never set them up. However, I have read that perhaps the unit tester is swallowing my exceptions?
Please advise me on how to change the behavior of Visual Studio, so I can track down these unhandled exceptions.
Thank you for your time.
The item may not be in the menu, which you can fix by customising the menu and adding the item to the debug menu.
You should also be able to get to the exceptions menu using CTRL + ALT + E
You need to tick the box in the "Thrown" column for Common Language Runtime exceptions (CLR)
i had the same issue. i opened the exceptions dialog and clicked the "Restore the list to the default settings" button and now it breaks on unhandled exceptions correctly.
there's probably a bug with upgrading from 2013.

Good Way to Debug Visual Studio Designer Errors

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

Resources