调试C#的可执行文件

调试C#的可执行文件

本文介绍了调试C#的可执行文件,在启动崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图远程调试C#程序。连接到主机不是问题,我可以看到这台机器上运行的所有进程,并可以连接到的 msvsmon.exe

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?

推荐答案

在启动时崩溃可能是由于缺少依赖性。运行 fuslogvw.exe 启动应用程序并看到任何绑定操作是否失败了。

Crashing at launch might be due to a missing dependency. Run fuslogvw.exe before starting your application and see whether any of the binding operations fail.

如果没有帮助,这通常是一个很好的做法,诊断日志到位。您可以使用专用的日志库,例如log4net的,或者至少你应该通过 System.Diagnostics.Trace 使用记录的最简单形式。您可以通过听跟踪消息在App.config配置跟踪侦听器或使用第三方工具,如调试或的DebugView 从Sysinternals的。

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:

System.Diagnostics.Debugger.Break();

我没有检查这是如何工作与远程调试器,但作为最后的手段,你可以有你的应用程序的睡眠足够长的时间让你附加一个调试器:

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:

System.Threading.Thread.Sleep(30000);

这篇关于调试C#的可执行文件,在启动崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 01:08