Enable editing after an unhandled exception in Visual Studio 2017 - c#

How can I continue execution after an unhandled exception in Visual Studio 2017?
In version 2015 and below this was easily done by clicking Enable Editing which "unwinds the callstack to the point before the exception". It was then possible to edit the execution point, variables and code.
This option is gone when a library throws the exception:
"".Substring(1);
In case the exception happens in user code it still works:
int x = 0;
Console.WriteLine(1 / x);
Notice the yellow arrow which can be dragged.
I really hope this feature was not removed because salvaging a crashing program (here, by setting x = 1 for example, changing the string constant or by skipping the problematic line) is something I do a lot. Right now I have a multi-hour operation 99% completed in this state and I'd really like to rescue it by suppressing an unimportant error.
This is Visual Studio 2017 build 26228 on .NET 4.6.1.

In VS2017 the old "Enable Editing" is hidden and triggered automatically. While debugging, I'm able to edit the code / variables after unhandled exception if I do the following:
Click in the document to take focus off the new Exception Helper
Hit spacebar (or your whichever key is your favorite!)
OR
Drag the yellow arrow (green arrow for library).
Before hitting a key or moving the arrow there is the padlock on the file tab telling you it's edit-locked. After, the lock is removed just like the old "Enable Editing" feature. That first keystroke that removes the edit-lock isn't entered into the file, after that, editing code and variables behaves just as before.
I preferred the explicit "Enable Editing" link as it was before, hopefully they bring it back.

Having run into this issue time and again, since I switched to 2017, I finally found this question, and found out that it actually works for exception from "My Code". Thanks for educating me on that!
But I was also wondering if it doesn't perhaps works on the "green arrow", and it actually works now! I'm running 15.2, so if it doesn't work for you yet, perhaps try upgrading to the latest version.

You can have the application not send exceptions to the debugger:
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
Works for me in VS 2017.

Related

C# Visual Studio - Able to step through breakpoints but not stopping at errors

I have a peculiar thing happening. I have am in Visual Studio 2019 and am able to step through breakpoints, but when I come to a line that has an error, it just throws an exception as if it is in a try / catch and just tripped the catch part.
What should happen is that visual studio usually shows/jumps to the line that has the error and shows the little dialog when you hover over the red circle with the white "X" in it to show what the error is.
Here are the things I have checked:
There are no try/catches in my code. only using statements.
I am in debug mode, not in release mode
My Define Debug constant is set to true
I am loading the correct .pdb file
"Enable just my code" is checked in the options.
my "Debuggin information" setting in Advanced build settings is set to "full"
I restarted visual studio
I restarted my computer.
Does anyone know how to fix this so that it shows the line and the error at which it breaks at?
update:
This is what it should show when a bug is found:
Of course, once I post my own question, I somehow figure it out.
This issue still confuses me but what fixed it for me was just adding this line to my form1_load:
throw new FileNotFoundException(#"show random bug here");
I suspect I could have added it anywhere, even in my main(), so long as it was tripped and "reset the debugger"
After putting this line in my code and running it, the broke at the line and showed everything correctly. After that, I was able to comment out the line and run my code. now the debugger shows where it's breaking normally and showing the line along with the error. weird.
I hope this helps someone in the future.

Error while trying to edit code in debugging mode in VS2013

I'm a C# programmer and recently I've installed Visual Studio 2013. The problem is when i set a break point or get an error and trying to edit the codes while debugging I get this error and I couldn't find the same error searching on Google.
Changes are not allowed for this module as it was not built for
changes while debugging or the target .NET runtime version does not
support it
I also tried to check the options on Tools -> Options -> Debugging -> Edit and Continue, But didn't help.
Any idea what the problem is?
To edit a C# program while you're running it in Visual Studio 2013:
Go to Project, Properties, Build.
Set Platform target: x86
Disable "Optimize code"
Set Advanced, Debug Info: Full
I came across the same issue and found that "solution configuration" on the top bar was changed to Release from Debug,because I build the last version into Release folder.Changing back to Debug mode will solve the issue.
The code your probably modifying is included in the exception. Since, your code is not posted here, I can't say. So please refer to this link and check whether it is really not allowed.
We just had the same issue in Visual Studio 2013 and in our case it was because we had disabled the Visual Studio Hosting Process on the Debug tab in Project Settings.
You can try
Right click 'Solution' in the Solution Explorer.
Select Properties.
Choose Configuration Properties from the left menu.
Select 'Debug' from the dropdown list in the upper-left corner labeled 'Configuration:'.
I just had the same problem and found a solution that worked for me right here after trying 100 other things:
https://stackoverflow.com/a/12543388/5367013
1.) execute VsPerfCLREnv /globaloff
2.) reboot your computer
In a Web Forms application, I initially received the "Changes are not allowed for this module as it was not built for changes while debugging or the target .NET runtime version does not support it" error message. Based on suggestions above I completed the following:
Right click the project name, just under the Solution name in Solution Explorer and select Properties, the "Build" tab
Set Platform target: x86 (Note, for me this was already set)
Disable "Optimize code"
Click the “Advanced” button (near bottom) and set, Debug Info: Full
I tried to modify code, but then I received the "Edit and Continue" window stating "Changes are not allowed while code is running."
Here was the important part: I can only make changes while stopped at a breakpoint. If the page is loaded, I get that same "Changes are not allowed..." message. So set a breakpoint to a line above where you need to make the change, complete the update and you should be set.
Or (as I subsequently discovered) another way to modify code without using a breakpoint is to click in Visual Studio "Debug/Break All" (Ctrl+Alt+Break), make your change and then press F5 or click the "Continue" button. (Using this method you will might need a page refresh to see the mods.)
It worked for me by unchecking "Enable optimizations" option.
Please refer below image for more info.

Visual Studio 2012 won't let me debug

I can't seem to be able to debug. When I try to, I don't get any build errors, and the layout changes to debug mode, but the windows never pops up. I have an orange bar at the bottom of VS, which I think is standard, but nothing happens after that. It's not just in the project I'm working on. I have started a new WFA and tried to debug without adding any code and the same thing happens. Anybody have similar issues?
I've encountered this before. Not sure what causes it, but generally it is one of a couple of things to fix it.
make sure you are building in debug and not release
close VS, go to the project's dir and delete the obj and bin directories. Reopen in VS and rebuild.
there is an option under tools - options - build (iirc) that allows for checking if source is same as code file. However, you should see a message in output window if this is the case.
on the project properties in the build (iirc) you can throttle the pdb file from full debug symbols to no pdb at all. If you are not the only person on the project check this setting still has full pdb enabled (low probability this got changed though)
make sure you're on the right platform that you are building to (x64 vs x32)
...lots more, but a starting place...
Addendum as per comment...
So, those messages are good. It is saying there are no problems (but it sounds like you already know that :) ). I would start with the general debug options you mention. Do this on a hello world app. That way you can troubleshoot the lowest common first. Here are my settings. Try to match them and see if that works. For example, I know "ask before deleting breakpoint" is irrelevant, but "break all processes when one process breaks" is important. So, I just added them all to make it easier to troubleshoot.
ALso, make sure you are getting a red dot here like so in your code in visual studio (I've seen instances where VS won't let you put this here):
Right click on the project
Click on the properties.
go to web.
Check the Box for Enable Edit and Continue .
Hope that helps :)
This is an issue with visual studio 2012. It doesn't ALWAYS show up. I've found that if you stop your program during debugging, or if you close the console window, this will almost always trigger.
However, letting it run to completion isn't enough either, sometimes this just happens.
Also you can build your application in debug mode, go to the output, run the program, and attach to that process. :P
Amazing answers already given but they dont help in the purpose. So here is my finding, no matter if i am late in answering, but it really works for me.
Even if you are developing a web app, just go to the website properties by right-clicking the project and then you see a "Web" tab on left as i have highlighted. Then just check the box saying "Enable Edit and Continue". Thats all you need to do. it works for me!
I had a similar problem, and solution was absolutely dumb. VS was confused with two instances of Internet Explorer in “Browse with” setting. So, I set Google Chrome (any browser) as default, and then set IE as default again. It deleted the other instance of IE (only one remained) and debugging was enabled.
Hope it help!
I had a similar issue.
I added up:
using namespace std;
and this solved the problem
For me, uninstalling the Redgate's Reflector plugin that had expired fixed it. I spent more than 4 hours uninstalling, rebooting, reverting to older code, etc etc..
When my default browser was changed to CHROME, I could no longer debug my User Interface. Setting IE back to the default browser fixed it. Alternatively you can attach the process plug-in during debug.
I had the same problem with my desktop application and as this forum says you should mark your project as a startup project, since visual studio has unmarked. It worked just fine for me an I believe it will help other people that may have this problem, since I believe you have finished this project.
One of my VB .NET Winforms projects wouldn't allow debugging.
This was due to the configuration manager set to 'Release' even though the toolbar dropdown indicated 'Debug'.
You need to select the mode dropdown and select the last option 'Configuration Manager' and ensure that the main project is set to 'Debug' and not 'Release'
Install Microsoft SSDTSetup.exe 450Kb and Close the SSDT tool during install. After installation open the SSDT tool and execute the script task and Component with breakpoint. Worked for me
try checking your output without debugging
Ctrl + F5
good luck

Visual Studio 2012 not compiling anymore after changes made

i recently installed VS 12 Service Pack 1.
Since then, i noticed Visual Studio doesn't compile my project on start if changes were made.
Normally if you start (debugging) a project which has some changes, it recompiles it and starts then. But now, i always get debugging errors like "this breakpoint can´t be reached, because the source code is unequal to the runtime code" or whatever.
It´s annoying to recompile it manually always before starting - I always forget that :-/
Is there any option to fix this?
Can you check if the build on run option is set?
You will find it under Tools->Options->Project and Solutions->Build and Run.
I dont have a good answer as to why this would have been flipped just via installing the update1.
I think that you should enter the Solution's Property Pages (by right clicking the solution in the Solution Explorer pane) and setting the 'build' check-box of the relevant project.

Checking for solution on application crash

How can i disable the "checking for solution" when a error occurs in my program?
What i want is that it directly goes to the error inside Visual Studio 2010. Now i have to wait like 1 minute before i can select debug and see my error.
Did not have this behavior before and not really sure what changed in the environmental settings.
I was debugging with 2 breakpoints when this behavior occurs every time a error happens outside the breakpoints.
This is a settings of the OS rather than of Visual Studio, to disable checking for solution feature on Windows 7 :
Click on start, type: Choose how to report problems, then change it to Never check for solutions .
If Visual Studio stops reponding it shows "Checking for solution".
At this stage VS is trying to fix the problem and promts to "send report" if user allows that.
It makes not so much sense to disable this, nor it is allowed in Visual Studio.
What if you put a tick on the check box:
Debug -> Exception -> Common Language Runtime Exceptions?
Does it stop immediately?

Categories