Visual Studio Breakpoint Warning - c#

When debugging my code, I often throw breakpoints in to check the values of local variables to make sure everything is on the right track.
Lately, when I make changes to my code and recompile, all my breakpoints turn into the outline of a circle (instead of a full red circle) and it gives me an error that reads;
The breakpoint will not currently be hit. No executable code is
associated with this line. Possible causes include: conditional
compilation or complier optimizations.
What's strange about this issue is that I can simply remove and add the breakpoint and everything will work completely fine.
I am not using any type of conditional compilation or complier optimizations. Does anyone know what this means or how to fix this? It gets quite annoying replacing 10-12 breakpoints each time I compile.

This can happen for a few reasons
The code the debugger is using is different from the code that the application is running
The pdb file that the debugger is using is different from the code that the application is running
The code the application is running has been optimized and debug information has been stripped out.
The code in which you have breakpoints on hasn't been loaded into the process yet (assuming the things above are not the culprits)
If you are attaching the debugger, pay attention to what .net framework it's attaching to (i've had issues with it using .net 4 when code was all .net 2.0)
The assembly you have is also in the GAC. This might happen if say you installed your program so you could debug it, but the installer put the dll in the GAC.
Remove the reference and re-add it (thanks to forsvarir). Typically this occurs when the project that is referenced is not in the solution, and VS will copy the dll from the bin directory of another project. You will know this was the issue when you try to re-add the reference, and can't find the project :)
It's pretty tough to figure out what's going on here, but i would suggest using the fusion log viewer to see what is being loaded and where it's being loaded from and then you can look at the dll and see if it's old code, etc.

Check the project settings
Make sure you don't check the code optimize option, and make sure debug symbols are checked.
Notice that when you change the configuration other settings might change as well and you might not see. Make sure the values are correct for the configuration you are attempting to compile.
Delete the output files
Physically delete all generated DLLs, PDBs and EXEs. Then compile again to generate the files. Sometimes Visual Studio can "get lost" and "forget" to overwrite the output files when you build your solution.
Restart your computer
It usually solves 99% of problems. I already had some issues with Visual Studio and restarting it or the computer solved the problem.

I know this is an old post but still timely enough as I was looking for any other reason I might be getting this problem.
That being said you also might want to check the "Temporary ASP.NET Files" in your c:\Windows\Microsoft.NET\[Frameworks] directories if you are creating a web application as these files are often the cause in my experience.

The use of the precompiler directive #line appears to affect the breakpoints behavior as well, as I've just discovered.

Adding this response to the old thread in case someone like me is tracking down this mystery in an older ASP.Net application. I had one Webform code-behind which did not respond to breakpoints with the "...no executable code..." debugger warning. It was doing my head in as all of the other pages were working fine. I'd done the clean, rebuild, purged the temporary ASP.Net files, no joy.
The culprit with this file was the inclusion of several #ExternalSource directives surrounding some of the member variable declarations. Once those were removed and the project rebuilt, the break point behavior was restored. Those ExternalSource lines were appearing in the generated section of the code-behind. Not sure why they were there.

Related

100s of errors that all go away when I view them?

I have hundreds of errors saying type or namespace doesn't exist (some are types and some are namespaces). When I click to view the error it initially opens the file and shows the squiggly line under code in question, however within a second or two the squiggly line disappears and so does the error.
After I finish opening up all the files with "errors", all the errors disappear and it compiles fine. However, if I close any the files then the error reappears for that file.
This happened after I tried to merge branches. Not really sure how to proceed to find the root of the issue, or whether there even is a real issue... maybe this is just some bug in Visual Studio and I need to do something to clear some kind of cache to fix the problem?
Please advise.
Update:
I have tried all of tymtam's suggestions but to no avail.
However, after deleting the .vs folder, now the errors don't even go away when I open the files so I can no longer build by doing that either.
I am thinking the error may have something to do with dll versions or something like that but I have tried to rebuild and replace all dlls with latest ones and that hasn't helped either.
The problem for me was an outdated version of the .net framework. The new assemblies I was referencing were 4.8 based but my projects were targetting the 4.6.1 framework. Updating the project files to target 4.8 fixed it.
IntelliSense, which is likely the source of these errors, sometimes takes time to adjust to changes caused by switching branches (or more generally code changes that happen suddenly).
Here are the steps that should help, in order:
(Re)building the solution
Restarting Visual Studio
Closing Visual Studio and deleting .vs folder in the root of the solution folder.
Finally you can see if the errors are 'real' by changing what the Error List window shows to Build Only. I would recommend to have it as 'Build + IntelliSense' normally, and using Build Only only on special occasions.
Focus on the 1st error
More generally, when dealing with a large number of errors it's not a bad idea to look at the first one only, solve it, and build the code. A single syntax error can result in many errors and trying to solve the 2nd and subsequent errors would be futile.
In addition to the above, make sure you also look at the warnings (possibly information messages).
In my case, I had them turned off to focus on the errors only and missed the fact that my two projects were set to different versions of the .NET framework.
I did these two things to fix my problem:
I used WinMerge to copy files from the old branch over everything in the new branch for the application in question.
I updated the framework on the project to the latest version.
Originally, I did those two steps except I used TFS to merge the old branch to the new (instead of using WinMerge to copy/overwrite files) and accepted the old version for all conflicts.
This was the nuclear option as I lost any changes that were made in the new branch :(. I have a copy that I can use WinMerge to try to manually merge changes back in but it's definitely frustrating.

Visual Studio Shows code errors that don't exist

I'm not sure if anyone else has encountered this but often, when I open this particular solution, I see a whole list of errors (see below).
If I double click one of them, then Visual Studio seems to wake up and the errors relating to that particular cs file disappear. This isn't a critical issue and is more on an irritation than anything else but I wonder, is there perhaps something wrong with my code that's causing this false-positive or is it random Visual Studio behaviour?
I had this problem too.
Deleting bin and obj folders not work.
Cleaning solution not work.
Various platform I need to be as is.
Helped me close solution and delete folder .vs, which is often full of problematic mess. After opening solution all false errors disappeared.
As mentioned in a comment, you can do a Clean and Rebuild. If that does not work for you, you can browse to the solution folder and within each of the project folders delete the bin and obj folders. Then perform a build.
You may also want to look into your Configuration Manager and ensure that all of your projects are set to the same Configuration (Debug/Release) and Platform (Any CPU/x86/etc...) and marked to build for that configuration.
Finally, you may also want to check the Build Order for your solution. Ensure that projects are all built in the proper order.
-- Edit:
On thing brought up in comments that I will add here was to make sure that any library projects in the solution are added as Project References rather than referencing the output DLL directly.
Something that has only become evident in later years, and is only relevant upon reflection on this old question, is that the particular solution that we experience this issue in contains a Website project and NOT a WebApplication project. This became evident when we started to look deeper into these recurring errors and noted that they only ever related to codebehind files and all had to do with the Control Name not existing in the current context.
Amongst the various differences between the two project types, it seems that the lack of designer files for each ASP page may be a contributing factor. The error disappears as soon as you double click it potentially indicating that VS is not able to keep track of the control references until you open the relevant page / codebehind file.
We're moving over to a Web Application as a temporary measure.
Hope this insight helps someone else!

Visual Studio 2012 "Step into" wrong function and Breakpoints not hit

I'm working on a Xamarin project and when I make an instance of a certain class a bearkpoint inside the constructor never gets hit. Just after instancing the class i call for a function of that class and the Step Into functionality of visual studio 2012 sends me to another totally unrelated function of another class.
When I comment that unrelated function that the Step Into sends me to and call the function again, the Step Into sends me again to a totally unrelated function of another third class.
The functions don't even have the same name.
I already cleaned, rebuild, manuallly deleted bin and obj and nothing works.
Any one knows what is happening?
Note: the Go To Definition (F12) command works as expected but the Step Into (F11) doesn't. I also have it on Debug mode instead of Release.
Well the problem here is obviously your debug symbols are out of sync with your source files. A few ways this can happen:
you're not actively building debug symbols (thus relying on older leftovers), or have optimizations enabled. Note that simply having the debug configuration selected doesn't mean this is not the case -- "debug" is just a label, you can name it puppies for all VS cares. Check the settings.
it's possible there's conflicts with the GAC or the symbol server trying to download wrong symbols. Check your file names that they're not too similar to system DLLs.
You mentioned Xamarin -- I'd triple check that it has the right symbols. It's possible following the call stack through out of date Xamarin symbols is screwing up things when it comes out and back into your code (events).
Another thing I'd try is to cold start your executable, then attach through VS. Go line by line in the Output window and see which symbols are loaded, and equally important, which are failing to load. Check your output folder, check the .pdb file names. Make sure you're not confusing things with the .vshost.exe file, you only care about the executable and any DLLs of your own.

breakpoint isn't hit when running 2 instances of the same project on VS2013

I created 2 instances of same project to apply different changes. So when I open project1 and debug class1, everything is smooth, I can have my breakpoints hit all other debugging features.
When I open project2 and close project1, I try to do same debugging on class1(some lines of the code is different), I get warning that
"the breakpoint will currently not hit. a copy of class1.cs was found in project1.dal.dll, but the current source code is the different from ther version"
When I close the VS completely and reopen the projects or If I clear the Temporary ASP.NET Files, Problem is getting resolved. But it happens everytime for me. so my questions are;
1) I wonder why does it happen and how can I resolve it without closing VS or clearing cache files?
2) I know the option called "Uncheck Require source files to exactly match the original version".. Is it safe to do it? or is there any side affects or disadvantages
It is impossible to debug your code in that way - you are creating different symbols for each build so when you debug one version, the other is not compatible with the previous one.
To make the long story short - you cannot debug one version of code when symbols from another version are loaded.
More info: Fixing "The breakpoint will not currently be hit. No symbols have been loaded for this document."
EDIT:
Check this link also: What is the "Temporary ASP.NET Files" folder for?

Enable and disable "Step into" debugging on certain project in a Visual Studio solution

I have a Visual Studio solution with four C# projects in it. I want to step into the code of a supporting project in the solution from my main project, but when I use the "Step into" key, it just skips over the call into that other project. I've set breakpoints in the supporting project, and they're ignored, and I can't for the life of me get it to step into any references to that project.
Everything is set to compile as "Debug", and I've seen Visual Studio warn me that my breakpoints won't be hit before - it doesn't do that in this case. It's as though it looks as though my code will debug, but then at run-time, there's a setting somewhere that tells Visual Studio not to step through the code in that project. All the other projects in my solutions debug without problems.
What box have I checked to cause this behavior?
UPDATE FOR CLARITY: The "Just my code" option is currently disabled. Also, since the code belongs to a project in my same solution, I don't think the "Just my code" option applies here. I thought it only applied to pre-compiled code that I didn't have the source for, but since I have the source in my project, I don't think this option has any effect.
Not sure if this is it, but "Tools>Options>Debugging>General:Enable Just My Code" is a possibility. (I prefer to always leave this unchecked.)
It turns out that the assembly needed to be copied into the GAC before it could be debugged. Under the debugging option "Just my code", there's an option to suppress an error if you don't have any user code, and it was suppressing the following error:
The Following mobile was built either
with optimizations enabled or without
debug information. (Module name and
path) To debug this module, change its
build configuration to Debug mode.
Since I was building it in Debug configuration, I searched on that error message and got this:
http://claytonj.wordpress.com/2008/01/04/the-following-module-was-built-either-with-optimizations-enabled-or-without-debug-information/
Problem solved. I don't know why it needs to be in the GAC in order for me to step into the project, but it does. I don't ask why, I just ask how, and then I do it...
One thing to check for is that your supporting project assembly has not been installed in the GAC. Open a command prompt and run the following to make sure...
gacutil /l assemblyName
You need to ensure the supporting projects have pdb files or else Visual Studio will not have the necessary information to step through the code.
If you have the source code for the dll's into which you are trying to step into, do the following:
Click on the project in which these dll's are added as reference and remove them.
Add the Project(s) corresponding to the dll(s) to the solution
Right click on the project -> Add Reference -> Choose the newly added Project(s).
Now set the break point and debug the code.. You will be able to step into the code.
The reason for the issue is because you program is still referencing the old dll (without the source code) as it has been added to your project as a reference. Once you remove that dll and add the Project (Source code of the dll) of the dll, Visual studio will be able to step into your code.
A couple of possibilities:
There is a check box to step into "just my code". Its intent is to make it so you can't step into Microsoft's Framework code (unless you choose to by unchecking the box).
You might try recompiling the supporting code to make sure the code you're debugging exactly matches the code file you're looking at. VS does care about this and will disable a breakpoint if you put it in the code file whose version doesn't match. Also, make sure the PDB file is in the same directory as the DLL.
In Visual Studio 2013 one way to cause this behaviour is to set build configuration to Release.
Put it back to Debug and see if that helps.

Categories

Resources