Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Cleaner Stack Traces in .NET/.NET Core

Cleaner Stack Traces in .NET/.NET Core

Leia em Português

This item in japanese

In exception-based languages, stack traces are one of the most important tools for diagnosing problems. In some cases, a brief error message and the stack trace is the only information a developer has available, especially when Personably Identifiable Information (PII) constraints limit what can be logged.

With the advent of the Task Parallel Library (TPL), and later async/await, stack traces have been getting increasingly difficult to understand. It is not unusual for the useful information to be hidden among multiple occurrences of:

And this is actually an improvement. Prior to .NET 4.5 and introduction of the ExceptionDispatchInfo class, stack traces couldn’t cross async boundaries and developers would instead have to dig through inner exceptions. But more can be done.

Illyriad games developer Ben Adams has taken it upon himself to improve the stack traces in .NET Core 2.1. His work focused on these areas:

  1. Remove the noise introduced by async/await call points.
  2. Show which method overload was being called when in an async or iterator context.

Meanwhile, Anirudh Agnihotry updated the KeyNotFoundException used by the Dictionary/ConcurrentDictionary to indicate which key wasn’t found, an annoyance for .NET developers going back to version 1.0.

If you are on .NET Framework or don’t want to wait for .NET Core 2.1, you can still take advantage of Ben’s work by using the Ben.Demystifier library. This goes beyond what his .NET Core changes did and makes the stack trace read much closer to the original C# code. (This wasn’t an option for .NET Core, as showing C# keywords in a VB or F# stack trace wouldn’t be helpful.)

.NET Core is published with the MIT license. Ben.Demystifier is available under the Apache license.

Rate this Article