I just had a problem hitting breakpoints in VS2015.
I am always using the solution configuration called Debug but for some reason my solution was set to build the Release version.
Switching from Release to Debug in the dropdown at the top of Visual Studio fixed my problem.
Answer from Helo on Stack OverflowI just had a problem hitting breakpoints in VS2015.
I am always using the solution configuration called Debug but for some reason my solution was set to build the Release version.
Switching from Release to Debug in the dropdown at the top of Visual Studio fixed my problem.
I've solved the similiar problem on VS2022 with test project using xunit by deleting launch settings file.
..\Properties\launchSettings.json
Breakpoint does not work during the test either with NUnit and MSTest. Visual Studio 2022, Net 6
Breakpoints not being hit...tried the usual suspects, still not working.
This is going to sound dumb but the project MUST be in debug mode to hit breakpoints.
edit: Sorry, I did not see that you found a solution. I think older versions of VS allowed you to hit a breakpoint either way.
More on reddit.com.net 7 xUnit Proj. Debugger Does Not Hit a Breakpoint in Visual Studio 2022
Debugging tests is not stopping on breakpoint
Videos
When i try debug tests and add a breakpoint at the first line, without any setup methods or anything prior, it runs the tests but wont hit breakpoints for some reason.
It also wont update the test, say I put a assert equals at the first line asserting that 1 = 0, it still goes to the previous error later in my test that shouldn't hit since the assert fails at the start
Is this a cache issue or a known bug?
SOLVED: my case was very niche where my database was in a perpetual restore state where we had a custom test runner which did stuff before any tests were run
However other solutions in the threads below are also very helpful for general help
Hi all,
I've got a multi-project solution (VS 2017) (about 20 projects). We've made some changes, and I'm trying to run the tests again.
Initially, the breakpoint would become "hollow" and the test would start and then very quickly shut down. I managed in the second that the breakpoint icon was visible, to hover over it and see the standard message "Breakpoint will not currently be hit. The source code does not match....etc".
Tried cleaning, then rebuilding. Forced VS to load the symbols from MS, deleted the obj/bin folders etc... ...and still nothing worked.
So, I checked for an upgrade, installed it. Now I get the same behaviour, but without the hollow icon when the test attempts to run/debug.
I've checked that all projects are using the same DotNet framework, and there's no conflicts with third-party libraries etc... I've changed them to x86 from "Any CPU"...all to no avail.
I'm fresh out of ideas at this point. I've googled and tried everything found on StackExchange etc...but none of those solutions are working.
I still cannot run a test...or hit a breakpoint if I run the program directly. All the projects are set to Debug.
EDIT: Got it. For some reason XUnit was missing files (no idea how). Reinstalled using NuGet (and upgraded at the same time), and now my breakpoints (solution wide!) have started being hit.
This is going to sound dumb but the project MUST be in debug mode to hit breakpoints.
edit: Sorry, I did not see that you found a solution. I think older versions of VS allowed you to hit a breakpoint either way.
I had a similar issue with my ASP.NET Core project. In my case it was caused by app restart on each request because my Startup() logic was populating web.config which in its turn was causing a new Startup(), and so on.
Spec: Win 10, Visual Studio Pro 2022 v17.7.4; .Net SDK v7.0.4
I have a solution with a bunch of different projects in it and one of them is a net7.0 xUnit Test proj. (converted from netstandard 2.0)
When I set a breakpoint to debug a test, it behaves like its just running a test instead of debugging it.
Looks like the debugger gets launched, but the breakpoint doesn't get hit. Test produces a result (After building for debug -> .pdb file is in the bin -> Debug -> net7.0 dir so I assume all symbols loaded)
I tried creating NUnit .net7.0 test -> same behavior.
I tried creating xUnit .net48 test proj -> weirdly debugger works as expected.
I tried putting Debug.WriteLine("In Debug!"). Debug output does not print the message.
Updated xunit.runner.visualstudio to 2.5.1. Didn't help.
Ran git clean -xdf on the repo, deleted all VS temp files, repaired VS through Installer, and reainstalled .net SDK (I wonder if, when I ran sdk installer, it might have detected that I already used the latest and hadn't actually reinstalled anything? but I doubt that's the problem) -> so all this didn't help.
--------
I left these for the end as these are solutions from other Stack Overflow posts that people ran into
7. I checked if the Debug Profile was missing; it wasn't. I created a new profile to make sure. Didn't help.
8. First, disabled all debugging settings in VS Tools -> Options -> Debugging -> General. Didn't help. Enabled all, didn't help.
9. Enabled/Disabled Hot Reload during debugging.
10. launchSettings.json is not in the projects.
11. In this [similar question](https://stackoverflow.com/questions/53827947/visual-studio-code-net-core-debugger-not-hitting-a-breakpoint) they recommend that I enable portable PDBs. Didn't help.
Thoughts: At this point I think its either some cached data thats interfering, or a .net bug. Debugger works as expected on a different computer (can't use different computer)
Throw your ideas at me. Thanks!
Try doing a full rebuild on the application. Pay attention that it's in the "Debug" configuration.
As far as I understand (but I'm not an expert in these things), this can happen when the debug info files (.PDB) are out of sync with the real compiled thing.
People.... I found other solution for breakpoint dont stop. In Attach to Process window on Visual Studio 2010 and using Framework 3.5, by default automatically determines the code types to debug (v2.0, v1.1, v1.0) and (v4.0).
Visual Studio gets confused and automatically determines 2.0 managed code as 4.0 managed code sometimes.
In this case you need to click in "Select..." button on "Attach to" field and select Manage (v2.0, v1.1, v1.0).
Regards
Thank you for reaching out!
You can try to start debugging your tests:
- Set Breakpoints: First, set breakpoints in the test methods that you want to debug. Since test methods can run in any order, make sure to set breakpoints in all the relevant test methods.
- Use Test Explorer:
- Open Test Explorer in Visual Studio (you can find it under the Test menu > Windows > Test Explorer).
- Select the test methods you want to debug.
- Right-click on the selected tests in the pane and select Debug.
- Select the test methods you want to debug.
- Open Test Explorer in Visual Studio (you can find it under the Test menu > Windows > Test Explorer).
This should start a debugging session where you can step through your code and inspect the flow and values.
I'm unable to view the screenshot you attached. Could you please share it again, It will be help us to resolve the issue.
Let me know if you need any further help with this. I will be happy to assist. If you find this helpful, Kindly mark the provided solution as "Accept Answer", so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
If you are having trouble firing unit tests in debug mode in Visual Studio 2022, here are a few steps you can take to troubleshoot the issue:
- Set Breakpoints: Ensure that you have set breakpoints in your test methods. Since test methods can run in any order, it's important to set breakpoints in all the test methods you want to debug.
- Use Test Explorer: Open Test Explorer by navigating to Test > Windows > Test Explorer. From there, you can select the test methods you want to debug, right-click, and choose Debug.
- Check Configuration: Make sure that your project is configured correctly for debugging. Sometimes, issues can arise if the project settings are not set to debug mode.
- Rebuild the Project: If the tests are not showing up in Test Explorer, try rebuilding the project to refresh the test list.
- Check for Errors: Look for any errors in the Output window that may indicate issues with test discovery or execution. For instance, if you see a
ReadOnlySpanerror, it may be related to a known MSBuild issue that can be resolved by renaming certain files in the Visual Studio installation directory. - Update Visual Studio: Ensure that you are using the latest version of Visual Studio 2022, as updates often include bug fixes and improvements that may resolve your issue.
If these steps do not resolve the issue, consider consulting the Visual Studio documentation or community forums for additional support.
References:
- Debug and analyze unit tests by using Test Explorer
- Unit testing JavaScript and TypeScript in Visual Studio