Are you compiling your code in debug mode? This tends to be the most common issue. Your code gets compiled with optimizations and your breakpoint is on code that was optimized away. At that point the debugger cannot map the breakpoint source back to your actual source code.
Ensure that you are compiling your project in debug mode by confirming that the solution configuration is set to Debug. This is generally shown in the toolbar.
However this is the solution configuration and it is possible that a project is using a different configuration so you should also go to Configuration Manager (from Solution Explorer by right clicking the solution) for your solution and ensure your project is building for Debug as well in this configuration.
Ensure you are doing a full rebuild and that no errors occur. If you accidentally told VS to run projects even on build errors then it is possible you're running an older build of your code which can also cause problems.
If the breakpoint works in the exe project but you're trying to set a breakpoint in a library project then it is possible the exe project is not using the built library project.
If none of that works then a last resort is to close VS, wipe the .vs
, bin
and obj
folders and then reopen and build your solution. This will reset everything including caches and breakpoints. Then try setting the breakpoint again.