Tutorial :The Visual Studio debugger is not attaching when at the root of a website


I have a problem with my Visual Studio 2008 debugger not attaching to the root of the default website when I run from within the environment.

I have a .NET 3.5 Web application project running on Visual Studio 2008 SP1. I have set the project to "Use Local IIS Web server" with a path of "http://localhost/". I am able to create the Virtual Directory and the application compiles fine.

My problem is that when Internet Explorer launches, the debugger is not connected. I am able to "Attach to Process" and choose "w3wp.exe", and it will debug just fine. This is a PITA; why will it not automatically attach?

I used to run this exact same project under a VD and never had an issue with the debugger not attaching. Thoughts?


The problem I was having was related to the fact that I had a tag in my web.config that surrounded my tag. This evidently causes the debugger to attach and then error out immediately without any sort of warning or error. Here is the article I used to figure this out:

Unable to debug Web Site with Top Level Location


Is web applications at the root of your website and at your virtual directory is completely identical?
Differences of behavior may be result of incorrect debug settings for your web site project. There are special options for different ways of debugging. One of them is instant attaching of debugger and waiting for external call to website (this is the one you possibly need).
Differences between web.config and IIS configurations may also be the reasons of different behavior.


I would try running Visual Studio using an administrator account.


I use this macro in Visual Studio which I wire up to a shortcut key in Visual Studio. It basically does what works for you, attaching to w3wp.exe with the debugger.

I had similar issues with the auto attaching not exactly working the way I expected on occasions. For me this works a treat. I also don't like Internet Explorer firing up automatically as I usually test in Firefox. So this macro doesn't trigger Internet Explorer autostart, which I like.

Imports System  Imports EnvDTE  Imports EnvDTE80  Imports EnvDTE90  Imports System.Diagnostics    Public Module AttachToWebServer        Public Sub AttachToWebServer()            Dim AspNetWp As String = "aspnet_wp.exe"          Dim W3WP As String = "w3wp.exe"            If Not (AttachToProcess(AspNetWp)) Then              If Not AttachToProcess(W3WP) Then                  System.Windows.Forms.MessageBox.Show(String.Format("Process {0} or {1} Cannot Be Found", AspNetWp, W3WP), "Attach To Web Server Macro")              End If          End If      End Sub        Public Function AttachToProcess(ByVal ProcessName As String) As Boolean          Try              Dim ProcessFound As Boolean = False              Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger              Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")              Dim dbgeng(10) As EnvDTE80.Engine              Dim indexer As Integer = 0                For Each myEngine As Engine In trans.Engines                  'Possible values here could be "T-SQL","Native","Managed","Workflow" "Managed/Native", "Script"                  If myEngine.Name.Equals("Managed") Then                      dbgeng(indexer) = myEngine                      indexer += 1                  End If              Next                Dim processes As EnvDTE.Processes = dbg2.GetProcesses(trans, "localhost")              For Each Process As EnvDTE80.Process2 In processes                  If Process.Name.Contains(ProcessName) Then                      Process.Attach2(dbgeng)                      ProcessFound = True                  End If              Next              Return ProcessFound          Catch ex As System.Exception              MsgBox(ex.Message)          End Try      End Function    End Module  


There is another cause that has the same nasty behavior.

If you have a solution that has multiple website projects, then Visual Studio will start all these projects, even if you have set only one of these website projects as the startup project. But, Visual Studio will only attach to the website that you have configured as startup project.

It's also possible to configure the solution to have multiple startup projects. If you configure the solution in such a way that Visual Studio will start all website projects then you will end up with the same situation as described above - that is: each website project has a running dev-webserver - but with the added advantage that Visual Studio is attached to all webservers.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »