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!