How to debug ASP.Net MVC in Visual Studio 2019 - c#

I was hunting a phantom-problem, until I recognized that the debugging wasn't working as expected.
I tried to debug some controller-code (c#) in my ASP.Net application and for this, I stopped the excecution, using a breakpoint (F9).
I started debugging with F5 and the code stopped, as expected at the breakpoint.
There, I tried to fetch some data, using different approaches.
None of the tries gave me the expected result so after a while, I recognized, that with every excecution the same compiled code is used and not the code, I was watching (and changing) in the editor.
I'm pretty sure, that in VS2017 it worked that way, so I could change the code while excecution.
How can I debug the C# code (and change the code) while excecution?
Thanks

You can do it in Vs2019 by In Tools > Options > (or Debug > Options) > Debugging > General, select Edit and Continue in the right pane.

Related

My visual studio ( 2019 ) doesn't show where the error came from

I use visual studio 2019 with iisexpress and swagger to test out my APIs, it used to work just fine whenever an error popped in swagger it would show me where the error came from and details about it, then I had to click continue in order to return the error to swagger.
So, whether be it a user handled exception or a common runtime language exception, visual studio used to give me information about that error before it showed it to the user.
However something changed with my settings and now the error doesn't show in my IDE anymore, it directly returns it to swagger which is making my job impossible.
What I have tried so far: Enabling/Disabling Just My Code, reloading symbols, checking that project is running with debug mode. All answers that I found here did not work for me.
If it is of any help, my breakpoints hit normally.

Application won't launch. Breakpoints aren't hit. No exceptions

My program worked fine up until 30 minutes ago when it just would not launch. I didn't change any code and all settings are the same. When I try to launch my application through visual studio it just does what it usually does then says "Ready". Nothing shows. If I try to debug the code by breaking it somewhere, the breakpoint says "The breakpoint will not currently be hit. The source code is different from the original version." Also visual studio freezes if I leave the supposedly running program going for longer that about a minute, then I have to end the visual studio task. There really isn't any code that I can show you for this.
What is going on and how can I fix it? Is my project corrupt somehow?
If this happened to me I would do:
Check Configuration ( Debug vs Release vs other)
Check Platform (AnyCPU or ....)
Make sure that they both are Debug and AnyCPU
Save solution
Clean Solution
Build each project starting with the one that has no dependencies
** UPDATE **
You posted this message
"0 succeeded, 0 failed, 1 skipped" –
When you Clean, there should be no skipped projects in the process of rebuilding

System.Diagnostics.Debug.WriteLine being stepped over

I am using Visual Studio 2013 in an ASP.NET MVC/C# project.
I am outputting to the output window using
System.Diagnostics.Debug.WriteLine
but for some reason VS has stopped running this line. I am executing in Debug mode. If I step through the code the debugger will jump over this line.
Is this controlled by a setting. I have searched the web but nothing obvious jump out
Go to project settings and see if there is check mark in front of Define DEBUG constant. Most likely that it's not there, although it should be by default.
If DEBUG constant is not defined - the method you are referring to is removed by compiler. That's why your debugger acts like code is not there.

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.

C# can't start debugging application in IDE

I have C# application built in VS2010. Recently I changed something in project properties and now I have strange problem:
I can't start debugging of my application (F5). When I press F5 project compiles but then nothing happens. Even if I put some dummy code to my program.cs main function ie MessageBox.Show() it's not executed.
I can build app using "Build solution", it compiles and executes with no problems
In project properties following options are enabled:
- Define debug consant
- Define trace constant
- Advanced bulid settings / Debug info - full
What should I change to be able to debug my app from IDE?
Try deleting .suo file. Make backup first!
Here is similar thread:
VS2010, F5 - Builds but doesn't run (WPF)
Shutdown and restart VS :) It's happened to me a few times before.

Categories