How to read a .NET stack trace
- Start at the innermost exception. "---> System.X: ..." lines are inner exceptions, and "--- End of inner exception stack trace ---" closes one. The outer exceptions were usually thrown by code that caught the inner one and wrapped it. The innermost one is the root cause.
- Then find the first frame of your own code. The frames above it are framework code that threw on your behalf (int.Parse, a Dictionary indexer, LINQ's First). Your line is where the bad value was passed in.
- Read compiler names as the code you wrote.
<>c__DisplayClass1_0.<Save>b__0is a lambda insideSave;<Save>g__Validate|0_0is the local functionValidateinsideSave;<SaveAsync>d__3.MoveNext()is the async methodSaveAsync(current .NET already prints that one asSaveAsync);Program.<Main>$is top-level statements. - AggregateException is a wrapper. Task.Wait() and .Result wrap failures in it; the real errors are its inner exceptions. With await you get the original exception instead.
Line numbers need the PDB
The "in File.cs:line 42" part comes from the PDB (debug symbols). A Release build writes a portable PDB next to the DLL; if deployment leaves it out, frames have no file and line. <DebugType>embedded</DebugType> puts the PDB inside the DLL so line numbers always survive. We checked all three on .NET 10.
FAQ
What is a stack trace?
The list of method calls that were active when an exception was thrown, innermost first. The first line after the exception message is the method that threw; the lines below it are its callers.
How do I get the full stack trace in C#?
Log exception.ToString(), not exception.Message. ToString() includes the type, the message, every inner exception and the stack traces. ILogger.LogError(exception, "...") logs it for you.
Why does my stack trace have no line numbers?
Line numbers come from the PDB file. If it is not deployed next to the DLL, frames show only method names. Deploy the .pdb, or set <DebugType>embedded</DebugType> to put it inside the DLL.
What does "End of stack trace from previous location" mean?
The exception crossed an await (or another rethrow with ExceptionDispatchInfo). The frames above the line ran before the rethrow, the frames below it after. It is one exception, not two.
Is my stack trace uploaded?
No. It is read in your browser.