.NET C# build RELEASE mode with full stack trace and line numbers

The default settings of .NET release builds excludes line numbers from the stack trace. Modify your project settings to see the line numbers even when built for Release.

Credits – this article is based on the information from:
http://stackoverflow.com/a/3137915 by Ben M
http://stackoverflow.com/a/628590 by Coxy
– and a comment from Gazeth
Google search

Modify project settings in Visual Studio (2013)

Select your project in Solution Explorer, then ALT+ENTER.
More information about optimized code (marked with blue) below.
Project settings

For web projects do even this

Uncheck “Exclude generated debug symbols”.
Web project settings

When publishing, use Release mode.
Web project publishing

Optimized code

.NET compilers use “inline” where useful. This is like instead of making a call to a small method, instead put the code in the calling method. That would give us a slightly different stack trace than without optimization (in debug mode).

Example of differences that may occur because of Optimize code. Method AssertTools.Assert is 2 lines of code.

public static void Assert(bool condition, string message)
{
    if (condition) return;
    throw new Exception(message);
}

Without optimization
release full debug - optimized