【发布时间】: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