我有一个exe在Visual Studio中正常工作。 当我将它部署到Windows Server时,它会崩溃 – 即使我试图捕获它的未处理的exception,如下面的代码所示。 代码DOES在VS中捕获未处理的exception(即在msg框中显示exception对象)。 当代码在服务器上崩溃时,它为我提供了在Visual Studio中“debugging”代码的机会,提供下面显示的读数。
Sub Main(ByVal args() As String) AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf errorReporter Dim myProcess As AutomatedProcessVB = New AutomatedProcessVB("Laphie") myProcess.run() End Sub Private Sub errorReporter(sender As Object, e As System.UnhandledExceptionEventArgs) MsgBox(e.ExceptionObject.ToString) Environment.Exit(3) End Sub
这是程序崩溃时的输出:
'AutoMatcher.exe': Loaded 'D:\Executables\AutoMatcher.exe', No native symbols in symbol file. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\ntdll.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\kernel32.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\sysfer.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\mscoree.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\advapi32.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoreei.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\shlwapi.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\gdi32.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\user32.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\msvcrt.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\imm32.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\msctf.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\lpk.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\usp10.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.6002.18305_none_5cb72f2a088b0ed3\comctl32.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\msvcr100_clr0400.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\16126cae96ea2422253ae06eeb672abc\mscorlib.ni.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\ole32.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Culture.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\nlssorting.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clrjit.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\rsaenh.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System\811a7bc79f8f0a5be8065292a320819e\System.ni.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Core\752225ca2585aa8f1c46b489e172e920\System.Core.ni.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Data.Linq\df6307904c34b42871857eb60ceb338f\System.Data.Linq.ni.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\Microsoft.VisualBas#\da70ab23582f4ebf61a2d551a390afcf\Microsoft.VisualBasic.ni.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Drawing\9422d0c052186760a4645e10995487f5\System.Drawing.ni.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Windows.Forms\caffbced23ee85b40b919ad4a122b7aa\System.Windows.Forms.ni.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.6002.18305_none_88f3a38569c2c436\comctl32.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Configuration\ed886fb71addf400705481dcf8de12da\System.Configuration.ni.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Xml\cb0c00757e89f0b1fe282913ed667212\System.Xml.ni.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\urlmon.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\oleaut32.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\iertutil.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\ntmarta.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\Wldap32.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\ws2_32.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\nsi.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\psapi.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\samlib.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\version.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\secur32.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\shell32.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\shfolder.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Data\90f1acbd79e2a5fabfb8c516d6be36a3\System.Data.ni.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\Microsoft.NET\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\crypt32.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\msasn1.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\userenv.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Transactions\102cfe160aeb1e16a35890004a421ec9\System.Transactions.ni.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\Microsoft.NET\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.EnterpriseSe#\6fc86a3e1d07ea824cd49b0c0b19d2f5\System.EnterpriseServices.ni.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.EnterpriseSe#\6fc86a3e1d07ea824cd49b0c0b19d2f5\System.EnterpriseServices.Wrapper.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\Microsoft.NET\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\security.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\credssp.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\schannel.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\netapi32.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\PwdSSP.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\kerberos.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\cryptdll.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\msv1_0.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\ntdsapi.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\dnsapi.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\mswsock.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\WSHTCPIP.DLL', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\wship6.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\nlaapi.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\IPHLPAPI.DLL', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\dhcpcsvc.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\winnsi.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\dhcpcsvc6.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\NapiNSP.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\winrnr.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\rasadhlp.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\dssenh.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\ncrypt.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\bcrypt.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\diasymreader.dll', No symbols loaded. 'AutoMatcher.exe': Loaded 'C:\Windows\System32\apphelp.dll', No symbols loaded. The thread 'Win32 Thread' (0x2d70) has exited with code 0 (0x0). Unhandled exception at 0x7719fc56 in AutoMatcher.exe: 0xE0434352: 0xe0434352. The thread 'Win32 Thread' (0x808) has exited with code -2146233082 (0x80131506). The thread 'Win32 Thread' (0x2a94) has exited with code -2146233082 (0x80131506). The thread 'Win32 Thread' (0x1d14) has exited with code -2146233082 (0x80131506). The thread 'Win32 Thread' (0x1ea4) has exited with code -2146233082 (0x80131506). The thread 'Win32 Thread' (0x221c) has exited with code -2146233082 (0x80131506). The program '[9572] AutoMatcher.exe: Native' has exited with code -2146233082 (0x80131506).
围绕整个程序的try-catch块捕获所有的错误并将它们写入文件
这是一个令人不安的选择。 如果程序在创建文件时遇到任何问题,那么肯定也会在创建日志文件时报告错误。 所以你也没有看到错误。 至少还要使用Console.WriteLine()。
这样的问题的一个典型的原因是您创建文件,而不指定文件的完整路径名称。 所以你会严重依赖于正确设置程序的默认目录。 从桌面启动时从命令行提示符启动时,这将不一样。 而且要小心,没有UAC标高的地方你可以写信的地方很少。 总是指定文件的完整路径名,使用Environment.GetFolderPath()来查找可写目录。