SqlRyan
SqlRyan

Reputation: 33924

Visual Studio detaches from application as soon as debugging starts

I have a web application that I've always been able to run in Visual Studio and it debugs just fine (breakpoints work, I can pause execution, etc). Recently, the behavior changed suddenly, and a few things happen:

Can anybody shed some light here?

Upvotes: 7

Views: 7891

Answers (7)

prem
prem

Reputation: 3548

In my case, I faced this issue with Visual Studio 2019 and 2022 as well. I tried upgrading/downgrading Visual Studio versions but nothing helped.

On debugging, I finally found the root cause and sharing it here to help others facing the same problem.

I was using Brave browser with Visual Studio and whenever I uploaded a file in my application, the Visual Studio debugging stopped automatically. The root cause of this issue is the feature in Visual Studio to stop debugging on closing the browser. With Brave browser Visual Studio feels like we have closed the browser on uploading the file. So to fix this issue I have turned of this setting as given here.

You can find this setting here Tools > Options > Projects and Solutions > Web Projects > Stop debugger when browser window is closed, close browser when debugging stops

Just turn it off and everything should work fine.

Upvotes: 0

jyoungdev
jyoungdev

Reputation: 2674

Just a workaround for those (like me) for whom the above solutions do not work: After starting the app you wish to debug, go to Debug -> Attach to Process, and attach it to the process you want to debug. Works on my machine.

Upvotes: 0

jesse
jesse

Reputation: 1

Quick windows 7 update: I had to add "localhost" to my list of trusted sites to correct this issue...go figure.

Upvotes: 0

Konstantin Salavatov
Konstantin Salavatov

Reputation: 4540

I've experienced samely looking behavior. The cause was in existence of several <system.web> sections (which is allowed by web.config schema). Visual Studio debugger (versions 2008 and 2010 were tested) looks in the first encountered section only. So if your <compilation debug="true"> tag is not in the first one, it thinks that there are no compilation.debug setting present and genrally tryes to add <compilation debug="true"> to the first <system.web>. In some cases VS2008 just silently procceds in this case. For example look here: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=510354#details"

Upvotes: 2

SqlRyan
SqlRyan

Reputation: 33924

It turns out that this was actually a result of an upgrade to Windows Vista. VS wasn't being "Run as an Administrator", which caused it to lack the rights to attach to other processes for debugging. As a result, debugging would stop right after it started. Changing the VS shortcut to run as an administrator resolved this problem.

Upvotes: 11

Dscoduc
Dscoduc

Reputation: 7754

I ran into something similar when I had placed some code in a constructor that was crashing. Exact same issues where the Debug would disconnect just after the application started up.

The short if it, check that you haven't configured a class constructor to run during web startup that is crashing...

Upvotes: 0

cjk
cjk

Reputation: 46475

Have you installed anything else on the server / workstation recently?

We have a third party app that doesn't allow us to debug, w3wp.exe crashes immediately upon an attempt to debug.

Upvotes: 0

Related Questions