这是我的场景:
关闭操作系统时,Receive 调用会出现未处理的异常:
Unhandled exception at 0x77438642 (KERNELBASE.dll) in myapp.exe.3180.dmp: 0xE0434352 (parameters: 0x80004005, 0x00000000, 0x00000000, 0x00000000, 0x71370000).
try/catch 块无法处理异常,即异常似乎没有包装到 .NET 异常中,并且没有命中下面的 catch 块:
try
{
return s.Receive(buffer); // <- the unhandled exception seen in a crash dump
}
catch (Exception ex)
{
Trace($"Receive error - ex: {ex}");
throw;
}
此未处理的异常不会导致 HRESULT 返回到本机代码并且进程崩溃。已注册的
AppDomain.CurrentDomain.UnhandledException
不会被触发。
当操作系统正常运行时,内部接收异常会被正确包装到 Exception 中,命中 catch 块并向本机代码返回 HRESULT。
我正在使用 WER 收集故障转储。此崩溃也会在应用程序 Windows 日志中记录为信息:
Fault bucket 1695090666501866404, type 1
Event Name: APPCRASH
Response: Not available
Cab Id: 0
Problem signature:
P1: myapp.exe
P2: 1.0.0.0
P3: 63984a64
P4: KERNELBASE.dll
P5: 10.0.20348.1249
P6: ac7a852c
P7: e0434352
P8: 00138642
P9:
P10:
异常的本机堆栈是:
KERNELBASE.dll!_RaiseException@16() Unknown
coreclr.dll!RaiseTheExceptionInternalOnly(Object * throwable, int rethrow=0x00000000, int) Line 2807 C++
coreclr.dll!IL_Throw(Object * obj=0x021463a0) Line 4119 C++
System.Net.Sockets.dll!6fb66362() Unknown
[Frames below may be incorrect and/or missing, native debugger attempting to walk managed call stack]
073689cd() Unknown
07368801() Unknown
0736843d() Unknown
073682c8() Unknown
coreclr.dll!@COMToCLRDispatchHelper@32() Unknown
coreclr.dll!InvokeStub(ComCallMethodDesc * pCMD, unsigned long pManagedTarget=0x021463a0, Object * orThis=0x0213efac, ComMethodFrame * pFrame=0x0191eea8, Thread * pThread=0x00b96d40, unsigned __int64 * pRetValOut=0x0191ee88) Line 197 C++
[Inline Frame] coreclr.dll!COMToCLRInvokeTarget(unsigned long) Line 342 C++
[Inline Frame] coreclr.dll!COMToCLRWorkerBody(Thread *) Line 457 C++
coreclr.dll!COMToCLRWorker(Thread * pThread=0x00b96d40, ComMethodFrame * pFrame=0x0191eea8) Line 560 C++
01d0d359() Unknown
.. the rest of the stack in myapp.exe ...
托管堆栈是:
KERNELBASE.dll!_RaiseException@16() Unknown
[Managed to Native Transition]
System.Net.Sockets.dll!System.Net.Sockets.Socket.Receive(System.Span<byte> buffer) Line 1495 C#
.. the rest of the stack in myapp.exe ..
您对如何继续调试有什么建议吗?
谢谢你。
根据您的日志,应用程序很可能正在尝试使用已在使用的端口。尝试识别正在使用的端口,然后终止该进程,然后再次尝试您的进程。我开始在 Win2016 中看到类似的行为,但在 Win2008 R2 和 Win2012 中都没有发生。下面是一些我用来在 Win2016 上进行故障排除的有用链接。