views:

992

answers:

4

I am having a problem with my Visual Studio 2008 debugger not attaching to the root of the default website when I run from within the enviroment. I have an .NET 3.5 Web Application project running on VS 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 IE 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 and I was curious if anyone knew why this will 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?

A: 

I would try running VS using Administrator account.

Bartek Szabat
I am an Administrator
bechbd
A: 

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.

Dmitriy Matveev
I have the settings in the project set to use IIS with the address set to https://192.168.1.150 which is configured to point to the correct directory
bechbd
Did you tried to open http://192.168.1.150/ instead of http://localhost/ ?
Dmitriy Matveev
A: 

I use this macro in VS which I wire up to a shortcut key in Visual Studio, it basically does what works for you, attach to w3wp.exe with the debugger. As 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 IE firing up automatically as I usually test in Firefox. So this macro doesn't trigger IE 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
Jafin
+11  A: 

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:

http://www.west-wind.com/WebLog/posts/466163.aspx

bechbd
I wish I could upvote you multiple times!
Jere.Jones
This totally saved me. My problem was that I had included a <location> tag around my <appSettings> tags (for reasons I won't mention) and that was causing the debugger to fail. Removing it solved the issue. Thank you!
jeremcc
This just saved my butt big time!
cadmium