I would like to debug a .NET application that fails immediately on startup (and exists without an error message or log), but I can't attach a debugger to it because the process exists almost immediately after I run it. I don't have the source code for the app, so I can't do "Start Debugging". I tried using a Visual Studio macro to start a process, attach to it, then break, but the macro is too slow and by the time it finds the process, the process has already exited:
Imports System
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module Module1
Sub RunAndAttach()
Try
Dim dbg As Debugger3 = DTE.Debugger
Dim trans As Transport = dbg.Transports.Item("Default")
Dim sysProc As Process = System.Diagnostics.Process.Start(New ProcessStartInfo("C:\Temp\CrashingApp.exe") With {.WorkingDirectory = "C:\Temp"})
Dim proc As EnvDTE90.Process3 = dbg.GetProcesses(trans, "ALLON-PC").Item("CrashingApp.exe")
If (Not sysProc.HasExited) Then
proc.Attach()
proc.Break(False)
Else
MsgBox("Process " + proc.Name + " has already has exited.")
End If
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
End Module
Is there a way to attach the debugger to a newly created process, like F5 does?
Thanks!
You can attach the Visual Studio debugger to a running process on a local or remote computer. After the process is running, select Debug > Attach to Process or press Ctrl+Alt+p in Visual Studio, and use the Attach to Process dialog to attach the debugger to the process.
To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.
Open Visual Studio in Administrator Mode, then Debug -> attach to process -> tick the check box "Show processes from all user", select w3wp.exe. Administration mode is required for debugging the source code.
When WinDbg is in dormant mode, you can attach to a running process by choosing Attach to a Process from the File menu or by pressing F6. In the Attach to Process dialog box, select the process you want to debug, and select OK.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With