Skip to content

Instantly share code, notes, and snippets.

@aelij

aelij/AsyncStackTrace.cs

Last active Feb 19, 2016
Embed
What would you like to do?
Improved async stack trace
// see the full featured library at
// https://github.com/aelij/asyncstacktrace
=== OLD ===
System.InvalidOperationException: X ---> System.DivideByZeroException: Attempted to divide by zero.
at AsyncStackTrace.Program.M3() in ...\AsyncStackTrace\Program.cs:line 45
--- End of inner exception stack trace ---
at AsyncStackTrace.Program.M3() in ...\AsyncStackTrace\Program.cs:line 49
at AsyncStackTrace.Program.<M2>d__2`1.MoveNext() in ...\AsyncStackTrace\Program.cs:line 37
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at AsyncStackTrace.Program.<M1>d__1.MoveNext() in ...\AsyncStackTrace\Program.cs:line 24
=== NEW ===
System.InvalidOperationException: X ---> System.DivideByZeroException: Attempted to divide by zero.
at AsyncStackTrace.Program.M3() in ...\AsyncStackTrace\Program.cs:line 45
--- End of inner exception stack trace ---
at AsyncStackTrace.Program.M3() in ...\AsyncStackTrace\Program.cs:line 49
at async AsyncStackTrace.Program.M2[TValue](?) in ...\AsyncStackTrace\Program.cs:line 37
at async AsyncStackTrace.Program.M1(?) in ...\AsyncStackTrace\Program.cs:line 24
@aelij

This comment has been minimized.

Copy link
Owner Author

@aelij aelij commented Jan 22, 2016

This code is mostly copied from System.Diagnostics.StackTrace and System.Exception, with a few simple modifications that much improve the way async stack traces are formatted. By skipping all the frames of awaiters (INotifyCompletion) and reformatting the generated async class name (IAsyncStateMachine) into a method name.

There is also an issue with remote stack traces (e.g. with WCF). I've started working on a solution (PrepareForAsyncRemoting) but it's not ready yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.