I’m trying to remotely debug a C# program. Connecting to the host is not problem and I can see all the processes on running on that machine, and can connect to the msvsmon.exe.
However, the program I want to debug crashes immediately on launch giving me no time to attach myself to it. Also launching the debug executable in question through a remote location does nothing. How can I attach a debugger before the crash?
Crashing at launch might be due to a missing dependency. Run
fuslogvw.exebefore starting your application and see whether any of the binding operations fail.If that doesn’t help, it is generally a good practice to have diagnostic logging in place. You can use a dedicated logging library, e.g. log4net, or at least you should be using the simplest form of logging via
System.Diagnostics.Trace. You can listen to the trace messages by either configuring a trace listener in the app.config or using third-party tools like a debugger or DebugView from Sysinternals.If you actually want to attach a debugger you can insert a breakpoint programmatically:
I haven’t checked how this works with a remote debugger, but as a last resort you can have your application sleep long enough to allow you to attach a debugger: