Question

Some of the users of my application experience strange crashes from different exceptions in System.Runtime.CompilerServices.AsyncServices

There is none of my code in the stack trace and I don't have a clue where to search for a cause or how to add additional logging to find the reason of the crash. Googling did not help.

Examples of exceptions are:

String reference not set to an instance of a String. Parameter name: s

Void 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) 
Void System.Windows.Threading.DispatcherOperation.InvokeImpl() 
Void System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object) 
Void System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 
Void System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 
Void System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) 
Void System.Windows.Threading.DispatcherOperation.Invoke() 
Void 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) 
Void System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) 
Void System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) 
Void 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 - Void MyProject.App.Main()
Object reference not set to an instance of an object.

Void 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) 
Void System.Windows.Threading.DispatcherOperation.InvokeImpl() 
Void System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object) 
Void System.Threading.ExecutionContext.runTryCode(System.Object) 
Void System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object) 
Void System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) 
Void System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 
Void System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) 
System.Object System.Windows.Threading.DispatcherOperation.Invoke() 
Void 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) 
Void System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) 
Void 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 - Void MyProject.App.Main() 

Additional information: I am targeting NET 4.0 and using Microsoft.Bcl.Async. First of the exceptions described above happened on a machine with Win 7 / NET 4.0

Update: I'll try to clarify the question.

It seems that these stack traces can appear if some exception happens in async method. Is there a way to find the place where original exception happened? Because it is very hard to debug such issues without knowing anything but the exception message.

Was it helpful?

Solution

Since it seems that noone knows a better solution, I'll post the one I used.

I found out that the original exception that caused one of these crashes is always triggering FirstChanceException event first.

So to know what is the cause of the exception I did the following:

  • Logging all FirstChanceException events and the details of corresponding exceptions.
  • Including few last logged FirstChanceExceptions data in the crash report.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top