VisualStudio 2017 - Debugger skips over code when using step into - visual-studio

What could cause VS 2017's debugger to skip stepping in to code? I've verified that the build is set to Debug and that the project's Properties->Build->Optimize code is unchecked. I've tried deleting all the source and output files from my computer and checked it out again from TFS, yet the issue still remains. I've tried logging in as a different account and uninstalling/reinstalling VS and neither resolved the issue. The debugger works fine if I set manual breakpoints and will hit them in portions it would otherwise not step into, but using Step into will often skip portions of my own code for no discernible reason.
Edit
So disabling Just My Code fixed it which I dont understand at all the code is in the same solution, although in two projects/assemblies. So I guess my answer would now be, why does VisualStudio think the middle/end of a method is not "My Code"

why does VisualStudio think the middle/end of a method is not "My Code"
According to msdn document:
Enable Just My Code
The debugger displays and steps into user code
("My Code") only, ignoring system code and other code that is
optimized or that does not have debugging symbols.
Even if all the code is in the same solution, although in two projects/assemblies, you still need make sure if it is optimized and have debugging symbols.
Note: Don't miss copy .PDB file to the compiling directory.

Related

Visual Studio 2015 debugging: Symbols cannot be loaded until I restart my computer

Recently, whenever I change something in my code, rebuild, and attempt to debug, I get the error "This breakpoint will not currently be hit, No symbols have been loaded for this document."
But then as soon as I restart my computer, everything is fine and I can debug properly. Why is this happening? It's really frustrating having to restart my desktop every time I try to debug my code. I've looked all over stack overflow and MSDN and can't find any solution to my particular problem. Any help is appreciated
"This breakpoint will not currently be hit, No symbols have been loaded
for this document."
(As for this error message, it's common error which has different causes. I can't give the most direct correct answer for this issue, I can only give you some tips for trouble-shooting. In order to avoid losing contact in the round-trip comments, I post those content as answer instead of comments.)
Since VS2015 have been released for long time, I would think this issue is a particular one, not found similar issues online.
First of all, please create a new simple project to check if this issue occurs in new project when debugging.
If it persists in new project, I think this issue has something to do outside environment like VS settings, VS config files or Debug options.
You can try:
1.Go Tools=>Import and Export Settings=>Reset all settings =>No,just reset settings=>Finish
2.Repair VS IDE since it seems to work well in the past, and just got the issue recently, so maybe something is broken for your IDE(In Control Panel find VS2015, right-click=>change=>repair). Also, make sure you have the latest VS2015 Update3 instead of earlier versions.
And if it works well in new project, then maybe the issue is about the whole project or solution itself. You can try:
1.Navigate to solution folder, close all vs instance, delete the .vs, bin and obj folders and restart VS to check if it helps.
2.Make sure you've loaded the required symbols, check the content in your Modules window during debugging, there's possibility you don't load necessary symbols successfully.
3.Check the output folder after your rebuild, check in folder like bin\debug folder if you have both the .exe and .pdb files. And make sure the .exe and .pdb files are up-to-date after your rebuild by checking their Date Modified.
Hope it helps and more info about the project type, dependencies would be better:)

"No symbols have been loaded for this document." But they have!

As you can notice
Symbols are been correctly loaded.
I just created a view GetCompanies.cshtml using the AddView shortlink
But, no matter what I do, I can't debug in the View.
What I did so far:
Close and Open Solution
Close and open Visual Studio
Shutdown all ASP.NET Development Server's
Deleted all Symbol Libraries .pdb
Clean Solution
Re-Build Solution
did not (yet) shutdown Windows 7 x64 :-/
Sometimes if you have a hard stop, Visual Studio temp cache will be screwed.
Clear the cache by deleting these folders:
C:\Windows\Microsoft.NET\Framework\<.net version>\Temporary ASP.NET Files\(ApplicationName)
C:\Windows\Microsoft.NET\Framework64\<.net version>\Temporary ASP.NET Files\(ApplicationName)
I am finding the same behavior from time to time when debugging silverlight. My solution is to clean the browser's cache (on latest IE click on the wheel button, Developer tools), as it sometimes will cache the binary files and not load the new ones.
Perhaps is could be the same with your views?
Been messing with this problem for a couple hours trying everything above. I finally changed my Target Framework to .NET Framework4.5 and it all started magically working.
This is always weird. I just had this problem and solved it with a full rebuild of the entire solution.
There was also another strange symptom, though: a new unit test that I had written using NUnit, mocking with NSubstitute, wouldn't pass because NSubstitute wasn't returning what I wanted it to return. I lost a few minutes trying to figure out if I did something wrong programming NSubstitute, then when I tried to attach the debugger to the NUnit GUI I saw that warning.
That's when I decided to do a full rebuild of the solution, and that worked for me.
So I guess the lesson to be learned is "before smashing your head against the wall, try a full rebuild".
For me, I somehow switched my target build to Release instead of Debug
Remember that views are actually compiled when you request the page (by default).
This means when you set a breakpoint in a view:
It shows the "No Symbols" error. This just means the view isn't
compiled yet.
It shows the breakpoint fine. This just means
that it found SOME compiled version of the page. Like the LAST working version...
So basically its not meaningful information to look at what it says when you mouseover the breakpoint in a view (at least in this regard)
If you are trying to debug this page, then you have a problem. Look at what the debugger is outputting to your BROWSER instead and fix that first. I think we'll be surprised about how many people are going to facepalm at this.
I had this problem with SL5 project (VS2012). And to fix this, I was needed to set "Silverlight" option enabled in %MyProjectName%.Web project properties, under Web tab.
In my case, the .PDB file was hosed (from which the symbols are loaded) in VS 2012, so performing a Clean and Build reconstructed the .PDB file and everything started workign again.
I was attempting to debug a deployed WCF windows services (compiled in Release mode) and had the exact same issue. Give this a shot...
Save All. You may even want to try to clean the solution
Rebuild all and install or deploy
BEFORE starting the service (or exe) I copied the .pdb files over to the install folder
Start the service (or exe) and attach the debugger to the process
Worked like a charm (finally) for me.
delete bin and obj directories
run solution again.
Note: Unless that cshtml loads at runtime the symbols are not loaded. On page load that breakpoint will be hit. So wait till control goes to that page

Visual Studio 2010 takes too long loading symbols, symbol file location cannot be removed

Visual Studio takes a lot of extra time loading symbols for external dlls which I'd rather not load. I have fiddled with my symbol settings in VS2008 and these settings seem to be affecting VS2010
How do I stop it loading 3rd party symbols?
I've tried:
devenv /resetuserdata
Tools > Options > Debugging > Symbols (I can't remove or uncheck the pdb file location of: "Environment Variable: _NT_SYMBOL_PATH")
I've cleared the above location like so: set _NT_SYMBOL_PATH=
actually this made a huge difference (it was previously SRVc:\symbolshttp://msdl.microsoft.com/download/symbols)
I've deleted everything from: %localappdata%\Temp\Temporary ASP.NET Files\root\
The next thing would be a VS re-install, failing that an OS re-install, but if it saves me 14 seconds every time I press debug it would be worth it.
Try Debug -> Delete All Breakpoints
Things to try
Tools > Options Debugging > General
Disable source server support
Enable just my code(just tested and greatly improved load times for me) -when to disable
Disable .NET framework source stepping (automatically disables just my code if selected)
Tools > Options>Debugging > Symbols
Only Specified Modules
Or All modules unless excluded and exclude those 3rd party
I was able to remove all checks under .pdb locations, but I had d:\refsrc\symbols as an added location
I had this trouble too. I did not think that I had set _NT_SYMBOL_PATH but somehow it was set to the path I use when using WinDbg. I figured this out by running ProcMon from the SysInternals Suite and filtered out everything except DevEnv.exe and saw what files it was trying to access when debugging my application.
I deleted the _NT_SYMBOL_PATH environmental, restarted VS and everything runs like it should.
I offer this not so much for the answer which was supplied in the initial question but as guidance on how to figure out what was wrong.
For me, I had previously turned on Debugging -> Symbols -> All modules and forgot to turn it off when I was done with a particular project. Turning off this setting greatly improved my load times.
I had this trouble too. And I fix it easily. Just do: Debug->Options and Settings->Symbols. In Symbols I checked Only Specified Modules. Everything works fine again. Hope this helps.

"One or more breakpoints cannot be set and have been disabled. Execution will stop at the beginning of the program."

I set a breakpoint in my code in Visual-C++, but when I run, I see the error mentioned in the title.
I know this question has been asked before on Stack Overflow (Breakpoints cannot be set and have been disabled), but none of the answers there fully explained the problem I'm seeing. The closest I can see is something about the linker, but I don't understand that - so if someone could explain in more detail that would be great.
In my case, I have 2 projects in Visual C++ - the production dsw, and the test code dsw. I have loaded and rebuilt both dsws in debug mode. I want a breakpoint in the production code, which is run via the test scripts. My issue is I get the error message when I run the test code, because the break point is in the production code, which isn't loaded up when the test starts.
Near the beginning of the test script there is a mytest_initialize() command. I imagine this goes off and loads up the production dll. Once this line has executed, I can put the breakpoint in my production code and run until I hit it. But it's quite annoying to have to run to this line, set the breakpoint and continue every time I want to run the test.
So I think the problem is Visual C++ doesn't realise the two projects are related. Is this a linker issue? What does the linker do and what settings should I change to make this work?
Thanks in advance. Apologies if instead I should be appending this question to the existing one, this is my first post so not quite sure how this should work.
[Update 1] I think Chris O has identified the problem. I'll add a further update if I'm able to work out how to use the project settings to make this work.
It sounds like you are using VC6, since you mention dsw files. I think that is as good as it gets in VC6, you have to manually add the breakpoint after your module is loaded from LoadLibrary. Actually, there might be a project debug setting, so you can specify which DLLs to load when debugging your project, that will keep your breakpoints enabled when hitting F5.
You can also try attaching the debugger after you know the mytest_initialize() has been called, that might keep your breakpoints enabled.
I had this issue sometimes, but always pass this with some code replacement actions.
Here is some guy post, how he had fixed it.
Hope it helps.
In my case i solved this by setting the DLL project containing the breakpoint as Active Project and changed Debug settings for this project (right-click project>>settings>>Debug tab) to point to the project that actually runs and accesses the DLL. "Executable for debug session:" and "Working directory:" should be set to the executable that you actually want to run and its corresponding directory.
Hope this is of any help.
right-click project>>settings>>Link tab
check on Generate debug info
check on Link incrementally

Visual Studio links although nothing has changed

I have a couple of VS 2008 projects (C++) that are linked every time I start a build, even though nothing has changed. i.e. I select "Build Solution", it compiles and links, I select "Build Solution" again, it doesn't compile anything, but links again.
This is quite annoying and I have checked everything that might cause it to link again.
Is there a way to find out why Visual Studio does or skips certain build steps?
Any input is appreciated!
I had some time to revisit the problem and a workmate gave me the tip to use "process monitor" from sysinternals to figure out which file is missing.
Lo and behold it worked! It turns out that Visual Studio insists on linking against a bunch of libs even if the app does not need it. Due to an unfortunate (I guess...) chain of events, one of the default library paths disappeared from Visual Studios global settings, so VS couldn't find this lib anymore ("coredll.lib" in my case).
This didn't affect the final output, because this lib is not needed at all, but it still triggered a relink every time.
There are two possible fixes:
1) Restore the path to this lib in the global Visual Studio settings
2) Use "$(NoInherit)" in AdditionalLibraries to get rid of the unneeded lib.
I used solution #1, because #2 needs to be done for each configuration of each project because can't be done via Property Sheets.
Rebuilding can be caused also by non-existing and unused .h files belonging to the project. Since they are unused, there's no warning nor error about missing files.
Using "Process Monitor" by Sysinternals as mentioned earlier was a great hint towards figuring out the reason.
Bit of a long shot but check the date/time stamp on any dependent DLLs you have. If they are in the future then a rebuild will occur.
Edit: Also have you tried opening the .vcproj files up in an editor to check if anything's unusual? You could also try recreating them from scratch, if that's possible.

Resources