【问题标题】:Exceptions in System.Runtime.CompilerServices.AsyncServices without my code in stack trace堆栈跟踪中没有我的代码的 System.Runtime.CompilerServices.AsyncServices 中的异常
【发布时间】:2014-03-28 17:48:25
【问题描述】:

我的应用程序的一些用户因 System.Runtime.CompilerServices.AsyncServices 中的不同异常而遇到奇怪的崩溃

堆栈跟踪中没有我的代码,我不知道在哪里搜索原因或如何添加额外的日志记录来查找崩溃的原因。 谷歌搜索没有帮助。

例外示例如下:

字符串引用未设置为字符串的实例。参数名称:s

无效 System.Runtime.CompilerServices.AsyncServices.b__0(System.Object)
System.Object System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,System.Object,Int32)
System.Object MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object,System.Delegate,System.Object,Int32,System.Delegate)
无效 System.Windows.Threading.DispatcherOperation.InvokeImpl()
无效 System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
无效 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,布尔)
无效 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,布尔)
无效 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object)
无效 System.Windows.Threading.DispatcherOperation.Invoke()
无效 System.Windows.Threading.Dispatcher.ProcessQueue()
IntPtr System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
IntPtr MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
System.Object MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
System.Object System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,System.Object,Int32)
System.Object MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object,System.Delegate,System.Object,Int32,System.Delegate)
System.Object System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority,System.TimeSpan,System.Delegate,System.Object,Int32)
IntPtr MS.Win32.HwndSubclass.SubclassWndProc(IntPtr,Int32,IntPtr,IntPtr)
IntPtr MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
无效 System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
无效 System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
无效 System.Windows.Threading.Dispatcher.Run()
System.Object System.Windows.Application.RunDispatcher(System.Object)
Int32 System.Windows.Application.RunInternal(System.Windows.Window)
Int32 System.Windows.Application.Run(System.Windows.Window)
Int32 System.Windows.Application.Run()
App.g.cs - 无效 MyProject.App.Main()
对象引用未设置为对象的实例。

无效 System.Runtime.CompilerServices.AsyncServices.b__0(System.Object)
System.Object System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,System.Object,Int32)
System.Object MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object,System.Delegate,System.Object,Int32,System.Delegate)
无效 System.Windows.Threading.DispatcherOperation.InvokeImpl()
无效 System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
无效 System.Threading.ExecutionContext.runTryCode(System.Object)
无效 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode,CleanupCode,System.Object)
无效 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object)
无效 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,布尔)
无效 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object)
System.Object System.Windows.Threading.DispatcherOperation.Invoke()
无效 System.Windows.Threading.Dispatcher.ProcessQueue()
IntPtr System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
IntPtr MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
System.Object MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
System.Object System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,System.Object,Int32)
System.Object MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object,System.Delegate,System.Object,Int32,System.Delegate)
System.Object System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority,System.TimeSpan,System.Delegate,System.Object,Int32)
IntPtr MS.Win32.HwndSubclass.SubclassWndProc(IntPtr,Int32,IntPtr,IntPtr)
IntPtr MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
无效 System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
无效 System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
System.Object System.Windows.Application.RunDispatcher(System.Object)
Int32 System.Windows.Application.RunInternal(System.Windows.Window)
Int32 System.Windows.Application.Run(System.Windows.Window)
Int32 System.Windows.Application.Run()
App.g.cs - 无效 MyProject.App.Main() 

附加信息: 我的目标是 NET 4.0 并使用 Microsoft.Bcl.Async。 上面描述的第一个异常发生在装有 Win 7 / NET 4.0 的机器上

更新:我会尽量澄清这个问题。

如果异步方法中发生一些异常,这些堆栈跟踪似乎会出现。 有没有办法找到原始异常发生的地方?因为除了异常消息之外,在不知道任何信息的情况下很难调试此类问题。

【问题讨论】:

  • 你做任何可能涉及某种异步回调的事情吗?任何 TPL / Task?任何BeginInvoke?任何ThreadPool?您提到 Bcl.Async - 您是否检查过是否捕获了所有工作异常?
  • 我正在使用异步/等待调用、任务和 TPL。是的,我正在捕获工人异常,但有很多代码,我想我可能会错过一些东西。我怎样才能找到在哪里寻找这个问题的原因?这个堆栈跟踪并没有给出太多:(
  • 这些堆栈跟踪看起来不正确。一方面,触发崩溃的方法应该被称为AsyncServices.<ThrowAsync>b__0()。请确保您的日志记录代码没有中断。
  • 记录代码肯定没有被破坏。它在那里存在了很长时间,并且总是正常工作。我实际上重构了一个大型应用程序,开始使用 async/await 而不是回调。

标签: c# multithreading exception asynchronous task-parallel-library


【解决方案1】:

由于似乎没有人知道更好的解决方案,我将发布我使用的那个。

我发现导致这些崩溃之一的原始异常总是首先触发 FirstChanceException 事件。

所以要知道异常的原因是什么,我做了以下操作:

  • 记录所有 FirstChanceException 事件和相应异常的详细信息。
  • 在崩溃报告中包括最后记录的少数 FirstChanceExceptions 数据。

【讨论】:

  • 谢谢梅菲斯托。我刚刚使用 FirstChanceException 事件通过其哈希码 (e.Exception.GetHashCode()) 将异常存储到字典中,因此当我的应用程序进入 UnhandledException 事件时,我可以检查该字典以查看是否有更详细的堆栈跟踪和日志而是那个。
  • 这对我也很有效。我偶尔会遇到异步异常的问题,而且追踪它们总是很痛苦。
猜你喜欢
  • 2012-07-11
  • 1970-01-01
  • 2012-01-11
  • 1970-01-01
  • 1970-01-01
  • 2011-08-07
  • 2018-12-03
  • 2014-03-07
  • 2011-10-21
相关资源
最近更新 更多