Visual Studio breakpoints not being hit
Asked Answered
G

33

101

I'm working with an ASP.NET MVC project that seems to be having some issues when attaching to the IIS process (w3wp.exe). I'm running the solution and IIS 8.5 on my own local machine so I wouldn't think that this has anything to do with our network. What's strange to me is that I'm able to hit the breakpoints on any other solution I debug locally.

The issue I'm having exactly is that the breakpoints turn to red, hollow circles and never get hit. Usually the fix for this is a Clean/Rebuild of the solution but this hasn't worked. I've confirmed the code is being updated by adding "throw new Exception" to a page and ensuring it shows the exception. Again, this problem is only happening with this one solution. Any other solution I run the debugger with works fine. I've also tried restarting the app pool, the website, IIS, and also my computer.

A few of the articles I read mentioned that anti-virus programs can block a remote debugger from accessing the process. However, the entire setup is contained on my local machine so it doesn't sound like that would be the issue. It does concern me a bit though because we recently hired a new IT guy that's been making a lot of changes to everyone's machine.

One other point to add that's unique about this web application is the binding in IIS. The binding is "*" in order to leverage some custom functionality related to subdomains.

In the meantime, I'll continue to look for a solution but if anybody has any ideas what may be causing this one solution to not debug properly I'd really appreciate it.

EDIT: Found a solution that suggested deleting the ASP.NET temporary files. No luck.

Glovsky answered 5/2, 2014 at 15:56 Comment(1)
Similar question #14107804Cholecyst
G
131

Solved. Ended up being an incorrect configuration selected in the debug menu. I had mistakenly switched it to a release configuration that could not load the symbols for the document. Switched it to a debug configuration and the breakpoints hit just fine now.

To add on to what Abacus mentioned below, it could also be a web.config transform that is messing with your build. In our case, we have Release configurations that remove the debug attribute from the web.config's compilation section. Below is a screenshot of an example and Visual Studio's dropdown list of build configurations.

NOTE: Also make sure your Platform is correct along with the configuration. In my case, Dev.Debug|Mixed Platforms does not correctly build the solution but Dev.Debug|Any CPU will.

Build Configuration List

Glovsky answered 5/2, 2014 at 17:53 Comment(3)
just to clarify the steps to fix this: Project, Properties, Build, Advanced, check the value of "Debug Info". If set to "none", you cannot trap code there in Visual Studio.Rhinoscopy
thank you. Small mistake but gave me big trouble :)Brume
A ha. Thanks for this post. Just resolved my issueDisoblige
C
48

I struggled forever trying to fix this. Finally this is what did it for me.

Select Debug->Options->Debugging->General

Tick Enable .NET Framework source stepping.

(This may be all you need to do but if you are like me, you also have to do the ones stated below. The below solution will also fix errors where your project is loading old assemblies/.pdb files despite rebuilding and cleaning.)

Select Tools -> Options -> Projects and Solutions -> Build and Run,

Untick the checkbox of "Only Build startup projects and dependencies on Run",

Select Always Build from the "On Run, when project are out of date" dropdown.

Curtain answered 5/1, 2016 at 21:52 Comment(4)
This worked for me, although it really slows down starting debug, running under docker container...so I had to disable it to start project faster.Rosenblast
This worked for me. I have no idea why the setting seems to have changed on it's own randomly but this fixed the issueCordiecordier
U Save my life.. Or my saturdayBaynebridge
This worked for me. My debugger just stopped stepping into breakpoint all of a sudden, without me making any changes, thank you so much.Hatty
R
38

Enable 'Managed Compatibility Mode'. Go to Tools->Options->Debugging and enable Managed Compatibility Mode.

Reavis answered 13/4, 2015 at 16:5 Comment(0)
S
21

In my case this solution is useful:

Solution: Disable the "Just My Code" option in the Debugging/General settings.

![enter image description here

Reference: c-sharpcorner

Shaitan answered 4/6, 2019 at 14:29 Comment(1)
Holy crap... that actually worked! been circling my inability to step for ages and this one did the trick. I thought JMC had to be enabled...Reprography
A
19

I know this is not the OPs issue, but I had this happen on a project. The solution had multiple MVC projects and the wrong project was set as startup.

I had also set the configuration of the project(s) to just start process/debugger and not open a new browser window.

Visual Studio Project Properties

So on the surface it looks as if the debugger is starting up, but it does so for the wrong process. So check that and keep in mind that you can attach to multiple processes also.

Silly mistake that left me scratching my head for about 30 minutes.

Attach to both processes

Anamariaanamnesis answered 6/7, 2015 at 7:4 Comment(0)
E
14

The issue was resolved by unchecking the

Properties > Build > Optimize Code

setting on the web page properties screen (under General).

Screenshot.

Eri answered 15/12, 2016 at 4:42 Comment(2)
YUP! I checked this to see what it did - forgot i clicked it, and a few months later couldn't figure out why it wouldn't stop on any debug points!!!Magnify
I can agree - this fixed it for me. Although a developer sitting right next to me, can debug with the setting checked. So not sure why this "works" for me and his works with the box checked.Yogh
C
9

Right click on your project, then left click Properties, and select the Web tab.

Verify whether the correct server is selected for your case:

  • IIS Local

  • IIS Express

Coleen answered 13/4, 2015 at 16:15 Comment(0)
F
5

Go to Visual Studio Menu:

Debug -> Attach to Process

And then click the Select button, as in the image below:

Attach to process

Then make sure the "Automatically determine the type of code to debug" option is selected, like this:

Select code type

Fingerbreadth answered 20/7, 2017 at 18:7 Comment(0)
C
4

I had the same issue in a Xamarin.Forms project. The fix was manually converting the PCL from .NET 4.6 to .NET Standard 2.0.

PCL Advanced Build Configuration

For Visual Studio Mac: make sure you do it for each project

mac-screenshot

Cavafy answered 26/11, 2017 at 8:44 Comment(0)
P
3

In Visual Studio 2017 you need to make sure you're not in release configuration mode.

  1. Open the build menu ddl
  2. Click configuration manager
  3. Change from 'release' to 'debug'

configuration manager debug

Petit answered 16/8, 2018 at 17:52 Comment(0)
L
3

One of my projects in my solution was set to Release mode. I changed it back to Debug mode, and the breakpoints are hitting now.

Leyba answered 25/1, 2019 at 7:31 Comment(0)
B
2

In my scenario, I've got an MVC app and WebAPI in one solution, and I'm using local IIS (not express).

I also set up the sites in IIS as real domains, and edited my host file so that I can type in the real domain and everything works. I also noticed 2 things:

  1. The MVC code debugging was working perfectly.

  2. Attaching to process worked perfectly too. Just when I was debugging it didn't hit the breakpoint in my API.

This was the solution for me:

Right click webapi project > properties > Web > Project URL

By default it points to localhost, but since I set up the site in IIS, I forgot to change the URL to the website domain (i.e. instead of locahost, it should say http://{domain-name}/).

Bunny answered 29/4, 2018 at 3:10 Comment(0)
C
1

If anyone is using Visual Studio 2017 and IIS and is trying to debug a web site project, the following worked for me:

  1. Attach the web site project to IIS.
  2. Add it to the solution with File -> Add -> Existing Web Site... and select the project from the inetpub/wwwroot directory.
  3. Right-click on the web site project in the solution explorer and select Property Pages -> Start Options
  4. Click on Specific Page and select the startup page (For service use Service.svc, for web site use Default.aspx or the custom name for the page you selected).
  5. Click on Use custom server and write

http(s)://localhost/(web site name as appears in IIS)

for example: http://localhost/MyWebSite

That's it! Don't forget to make sure the web site is running on the IIS and that the web site you wish to debug is selected as the startup project (Right-click -> Set as StartUp Project).

Original post: How to Debug Your ASP.NET Projects Running Under IIS

Casuist answered 19/10, 2017 at 14:6 Comment(0)
C
1

In my case I had a string of length 70kb. Compiler did not thrown any error. But Debugger failed to hit the break point. After spending 3 hours and scratching my hair I found the cause for not hitting the break point. After removing 70kb data break point worked as normal.

Cardin answered 24/12, 2020 at 14:33 Comment(0)
N
1

It might also be (which was the case for my colleague) that you have disabled automatic loading of symbols for whichever reason.

If so, reenable it by opening Tools -> Options -> Debugging -> Symbols and move the radiobutton to "Load all modules, unless excluded"

enter image description here

Navigable answered 5/1, 2021 at 12:10 Comment(0)
P
1

I hate to admit missing something so simple, but hopefully this will help someone else. In my case, I am using local IIS and the website is running on an application pool, so when you attach the debugger to a process, be sure to checkmark "Show processes from all users" so that you can select the appropriate process.

"Attach to Process" with "Show processes from all users" checkmarked

Prototrophic answered 3/11, 2021 at 0:40 Comment(1)
I tried many things, wasted three hours until I found this. When debugging normally I'd see the Diagnostic Tools open momentarily but it would close. I attached to w3wp manually, ran my web application and viola, breakpoints are hit.Caw
C
1

click on Debug. Select [Debugging]. Select the [General]. Disable the "Just My Code" Click [OK] and rebuild the project.

Cormophyte answered 2/5, 2022 at 6:17 Comment(0)
W
0

If none of the above work, double-check your code. Sometimes the reason why the breakpoint appears to not be hitting is due to the block of code containing the breakpoint is not being executed for sometimes inadvertant reasons.

For example, forgetting the "Handles Me.Load" has gotten me a few times when copying and pasting code:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    --this block of code will not execute
    End Sub 

vs

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    --this block executes
    End Sub
Wilona answered 28/11, 2016 at 5:21 Comment(0)
P
0

You can't hit breakpoints while attached to IIS process if you haven't logged into your Microsoft account in VS2017.

Pulver answered 8/2, 2018 at 10:26 Comment(1)
I've found no proof of this.Dede
C
0

In my case the actual process was different from the original started process.

Usually we bind the local-hosted services through the w3wp.exe process. In my case a custom process was used. Changing to that solved the problem.

One more thing, change from Release to Debug mode. In release mode PDB files are not getting updated with breakpoints details. So make sure you are debugging your application in Debug mode.

Crispin answered 17/8, 2018 at 14:53 Comment(0)
H
0

Right click on your project, then left click Properties, and select the Web tab. Debuggers > ASP.NET

Hooten answered 12/4, 2019 at 12:26 Comment(0)
J
0

My case is not mentioned here:
I have to run the web project on a fake domain (settup on IIS and /hosts/etc) because of the callbacks from a third party site.

I was seeing two w3wp processes in the process list of VS:
w3wp.exe User Name: IIS APPPOOL\Default app pool
w3wp.exe User Name: IIS APPPOOL.svc

I had to to manually attach to second one to be able to debug.

So I realised the app pool of my Fake domain in iis is not set to "Default app pool"

enter image description here

https://manage.accuwebhosting.com/knowledgebase/2532/How-to-change-application-pool-from-IIS.html

As soon as I changed the domain's app pool to the "Default app pool" visual studio started to debug the web app.

Jea answered 20/2, 2020 at 2:44 Comment(0)
P
0

If any of your components are Strong Named (signed), then all need to be. If you, as I did, add a project and reference it from a Strong Named project/component, neglecting to sign your new component, debugging will be as if your new component is an external one and you will not be able to step into it. So make sure all your components are signed, or none.

enter image description here

Pickford answered 13/8, 2020 at 7:23 Comment(0)
P
0

In my case with 20+ projects in one solution, I included the project (I would like to debug) in the solution startup

Right-click solution-->Startup Project->Multiple startup projects->For project you want to debug select "Start" in action.

Now you should be able to hit those break points, especially projects which may be helper classes.

Phrasing answered 15/5, 2021 at 16:12 Comment(0)
C
0

in some cases the cases the problem is in IIS. if your debug worked and suddenly stopped working , use IISReset to reset the IIS thread-pools.

Centimeter answered 23/9, 2021 at 10:47 Comment(0)
C
0

In my case , changing Solution Platform from x86 to Any Cpu solved the problem.

Ciborium answered 30/12, 2021 at 13:30 Comment(0)
C
0

I just ran into this problem. What worked for me was to change Active Solution Platform to x86 instead of AnyCPU;

  1. Click Build
  2. Click Configuration Manager
  3. Select x86 from the Active Solution Platform Combobox.
Cogen answered 3/1, 2022 at 22:27 Comment(0)
M
0

Just another reason why breakpoint might not get hit: I replaced the reference to the DLL by a reference to the project. Upon build, no PDB file got created and so no breakpoint got hit. The Problem was that I forgot to do the same with the other projects in the solution. After replacing the references (DLL >> project) in all projects, the PDB got created and breakpoints worked like expected.

Marinate answered 4/1, 2022 at 23:45 Comment(0)
G
0

To delete project's bin and objects folders may be helpfull

Giselagiselbert answered 11/11, 2022 at 11:14 Comment(0)
L
0

Another reason a breakpoint might not be hit is that you are not debugging the site that you think you're debugging, due to anomalies in your site links. Case in point: Assume, when starting the debugger, that it normally launches a localhost page (as shown in the browser address bar). If reaching the breakpoint code entails first clicking a link on that localhost page to go to a different page, you must ensure the browser is still pointing to localhost after the click. If it's not, then your breakpoint will never be hit and you have to fix your links first. Kind of an obvious problem, but easy to overlook.

Lutist answered 18/11, 2022 at 3:14 Comment(0)
K
0

Disable: Go to Tools->Options->Debugging->'Enable just my code'

Snapshot

Krone answered 9/1, 2023 at 6:4 Comment(0)
A
0

For me, it was testing residues. I played around with different frameworks, changed the targeted framework in console app to .NET Standard for some silly reason. And when I came back and tried to debug something, breakpoints wouldn't work. Changing back to .NET 7 solved the issue. Changing to anything that actually supports proper execution will solve it as well. Surprising that I was able to run it anyway like that.

I had this in my .csproj file:

<PropertyGroup>
  <OutputType>Exe</OutputType>
  <TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

Change the TargetFramework property:

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
  </PropertyGroup>
Angora answered 17/4, 2023 at 18:15 Comment(0)
R
0

I was using visual studio 2022 and the breakpoints were not triggered , I sorted the issue by upgrading my project from .net 3.5 to 4.7

Romaineromains answered 12/9, 2023 at 16:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.