【发布时间】:2017-05-14 09:37:40
【问题描述】:
我有一个 C# .NET 4.5.2 windows 窗体应用程序,我使用任务和等待体系结构实现了它。最近我在应用程序中看到了一个奇怪的行为。尽管我使用了很多 try-catch 语句,并且几乎每一种异常都被处理了几次(每 3 或 4 天),但我收到了 X 停止工作的消息,但应用程序中没有任何日志。
我在事件查看器中只有两个条目,第一个是 .NET 运行时类型,第二个是应用程序错误。
对于日志记录,我使用 serilog 记录到控制台和滚动文件。出于远程通信目的,我使用 Slack(我认为这是问题的根源)。
这是日志的内容:
Application: X.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
at SlackAPI.RequestState`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].GotResponse(System.IAsyncResult)
at System.Net.LazyAsyncResult.Complete(IntPtr)
at System.Net.ContextAwareResult.CompleteCallback(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Net.ContextAwareResult.Complete(IntPtr)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(System.Object, IntPtr)
at System.Net.HttpWebRequest.SetResponse(System.Exception)
at System.Net.HttpWebRequest.SetAndOrProcessResponse(System.Object)
at System.Net.ConnectionReturnResult.SetResponses(System.Net.ConnectionReturnResult)
at System.Net.Connection.CompleteConnectionWrapper(System.Object, System.Object)
at System.Net.PooledStream.ConnectionCallback(System.Object, System.Exception, System.Net.Sockets.Socket, System.Net.IPAddress)
at System.Net.ServicePoint.ConnectSocketCallback(System.IAsyncResult)
at System.Net.LazyAsyncResult.Complete(IntPtr)
at System.Net.ContextAwareResult.Complete(IntPtr)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(System.Object, IntPtr)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)
Faulting application name: X.exe, version: 1.5.0.0, time stamp: 0x5914053a
Faulting module name: unknown, version: 0.0.0.0, time stamp: 0x00000000
Exception code: 0xc0000005
Fault offset: 0x0655a904
Faulting process id: 0x1bb0
Faulting application start time: 0x01d2ca214de3853b
Faulting application path: PATH-TO-X.exe
Faulting module path: unknown
Report Id: 5ef2a70f-387a-11e7-9c66-000c29bbc8ee
为了与 Slack 通信,我使用SlackAPI。 有什么建议吗?
更新:如何处理线程和任务未处理的异常。在program.cs Main函数中放一个全局try catch是否正确?
【问题讨论】:
-
看起来你崩溃的核心原因是
NullReferenceException。也许您想从检查导致它的代码部分开始,看看那里可能是null。 -
其实我也不知道在哪里。
-
如果您不知道问题出在哪里,您希望如何解决?就此而言,您希望我们如何解决它?
-
您应该在 SlackApi github 上创建一个问题。任何库都不应该在生产环境中抛出 NullReference,而他们的库会抛出 NullReference(根据您的堆栈跟踪)。
-
您可以使用
AppDomain.CurrentDomain.UnhandledException或Application.ThreadException。
标签: c# winforms slack-api slack serilog