Need help with AsyncFriendlyStackTrace?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

aelij
204 Stars 19 Forks MIT License 31 Commits 0 Opened issues

Description

Async-friendly format for stack traces and exceptions

Services available

!
?

Need anything else?

Contributors list

# 31,643
C#
avaloni...
c-sharp
Univers...
22 commits
# 474,697
C#
stack-t...
netstan...
Shell
3 commits
# 621,728
C#
stack-t...
netstan...
1 commit
# 82,924
message...
c-sharp
service...
net-fra...
1 commit
# 5,545
c-sharp
linq
Univers...
logging...
1 commit

Async-Friendly Stack Trace

Async-friendly format for stack traces and exceptions.

NuGet

Also check out Ben's Demystifier which resolves async, iterators, tuples, location functions and more.

System.Exception: Crash! Boom! Bang!
   at async AsyncFriendlyStackTrace.Test.Example1.C(?) in C:\Source\Repos\AsyncFriendlyStackTrace\src\AsyncFriendlyStackTrace.Test\Example1.cs:line 26
   at async AsyncFriendlyStackTrace.Test.Example1.B(?) in C:\Source\Repos\AsyncFriendlyStackTrace\src\AsyncFriendlyStackTrace.Test\Example1.cs:line 20
   at async AsyncFriendlyStackTrace.Test.Example1.A(?) in C:\Source\Repos\AsyncFriendlyStackTrace\src\AsyncFriendlyStackTrace.Test\Example1.cs:line 15
   at async AsyncFriendlyStackTrace.Test.Example1.Run(?) in C:\Source\Repos\AsyncFriendlyStackTrace\src\AsyncFriendlyStackTrace.Test\Example1.cs:line 10
   at AsyncFriendlyStackTrace.Test.Program.Run[TExample](TextWriter writer) in C:\Source\Repos\AsyncFriendlyStackTrace\src\AsyncFriendlyStackTrace.Test\Program.cs:line 45

Install

Install-Package AsyncFriendlyStackTrace

Usage

To format exceptions, use the extension methods in

ExceptionExtensions
:
exception.ToAsyncString();

This produces an async-friendly format, as you can see in the examples below. There is also special handling for

AggregateException
s and
ReflectionTypeLoadException
(which can contain multiple inner exceptions).

The main formatting work is done by the

StackTraceExtensions.ToAsyncString
extension method. The async-friendly formatting is archieved by: * Skipping all awaiter frames (all methods in types implementing
INotifyCompletion
) and
ExceptionDispatchInfo
frames. * Inferring the original method name from the async state machine class (
IAsyncStateMachine
) and removing the "MoveNext" - currently only for C#. * Adding the "async" prefix after "at" on each line for async invocations. * Appending "(?)" to the method signature to indicate that parameter information is missing. * Removing the "End of stack trace from previous location..." text.

Example outputs

In all the examples, OLD refrers to

ToString()
output, while NEW is
ToAsyncString()
.
  • Example 1 (code): A simple 3 async method chain.
  • Example 2 (code): Async invocations with a synchronous
    Wait()
    in the middle, causing an
    AggregateException
    .
  • Example 3 (code): Bad Serialization - When exception is serialized and deserialized, its stack trace is saved as string. So we can't reformat the stack trace. The "new" stack trace is still a bit shorter due to an improved
    AggregateException
    formatting (the first inner exception isn't repeated twice).
  • Example 4 (code): Good Serialization - We use the
    PrepareForAsyncSerialization
    before serializing the exception. This saves the async-friendly stack trace as a string in the
    Data
    dictionary of the exception. This has two downsides:
    • The serialized data will now contain both stack trace formats.
    • When using the
      DataContractSerializer
      , you must include
      exception.Data.GetType()
      as a known type. This is because its concrete type (
      ListDictionaryInternal
      ) is internal.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.