Sign up for our newsletter and receive a free copy of our book .NET Web Application Logging Essentials
"What a great idea, ELMAH (Error Logging) for .NET in the cloud."
Online pretty print of .NET stack traces
Stack Overflow (and the web in general) is filled with too many unformatted .NET stack traces. Using elmah.io's stack trace formatter, you can pretty print and either copy or download a nicely formatted stack trace. Paste the stack trace directly into your question/answer on Stack Overflow or download a screenshot to use on your blog.
If you want to save a stack trace for later use or create a link to it, click the Share button store the stack trace. Sharing stack traces on elmah.io works pretty much like gists on GitHub, but are nicely formatted and provides the visitor of your stack trace with the options for copying and saving a stack trace.
Stack traces in .NET is a presentation of the steps (called stack frames) touched to end up at a specific place in the code. Stack traces are typically used to describe the previous steps before the code threw an exception, but can be used for other purposes as well. Knowing about stack traces and how they are constructed will help you a lot when needing to debug failing code.
A typical stack trace will look something similar to this:
System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.Number.ParseInt32(ReadOnlySpan`1 value, NumberStyles styles, NumberFormatInfo info)
at System.Int32.Parse(String s)
at MyNamespace.IntParser.Parse(String s) in C:\apps\MyNamespace\IntParser.cs:line 11
at MyNamespace.Program.Main(String[] args) in C:\apps\MyNamespace\Program.cs:line 12
The first line always contains the fully qualified name of the thrown exception as well as the Message
property logged alongside the exception.
In the following lines, you see the chain of events leading up to this FormatException the stack frames should be read from the bottom up. The Main
method calls the Execute
method which again calls the Parse
method and so on. Each stack frame is shown in the following format:
at <Namespace>.<Class>.<Method>(<Parameters>) in <Location>:line <Line-number>
As shown in the stack trace above, some lines may not include the file location and line number. This depends on the assembly including the class and method has been built with debug symbols or not. A quick guide to include this information in your code is available here: Include filename and line number in stack traces.
Stack traces are sometimes 100% or partially obfuscated like this:
System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.Number.ParseInt32(ReadOnlySpan`1 value, NumberStyles styles, NumberFormatInfo info)
at System.Int32.Parse(String s)
at A.D.E(String x)
at A.B.C(String[] args)
You may also see stack traces looking more like this:
System.FormatException: Input string was not in a correct format.
at void Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at int Number.ParseInt32(ReadOnlySpan value, NumberStyles styles, NumberFormatInfo info)
at int int.Parse(string s)
at int MyNamespace.IntParser.Execute(string s)+() => { } in C:/apps/MyNamespace/IntParser.cs:line 11
at int MyNamespace.IntParser.Execute(string s) in C:/apps/MyNamespace/IntParser.cs:line 12
at void MyNamespace.Program.Main(string[] args) in C:/apps/MyNamespace/Program.cs:line 13
In this example various information has been added to the stack trace like the return type of the invoked method in each stack and better visualization of using C# lambdas. Enriched stack traces like this are available by installing stack trace improving NuGet packages, in this case the awesome Ben.Demystifier
package by Ben Adams.
If an exception contain an inner exception, this is shown in the stack trace too:
System.ApplicationException: Error during execute
---> System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.Number.ParseInt32(ReadOnlySpan`1 value, NumberStyles styles, NumberFormatInfo info)
at System.Int32.Parse(String s)
at MyNamespace.IntParser.Execute(String s) in C:\apps\MyNamespace\IntParser.cs:line 13
--- End of inner exception stack trace ---
at MyNamespace.IntParser.Execute(String s) in C:\apps\MyNamespace\IntParser.cs:line 17
at MyNamespace.Program.Main(String[] args) in C:\apps\MyNamespace\Program.cs:line 13
As seen in the example the code caught a System.ApplicationException
that has an inner exception of type System.FormatException
.
We monitor your websites for crashes and availability. This helps you get an overview of the quality of your applications and to spot trends in your releases.
We notify you when errors starts happening using Slack, Microsoft Teams, mail or other forms of communication to help you react to errors before your users do.
We help you fix bugs quickly by combining error diagnostic information with innovative quick fixes and answers from Stack Overflow and social media.