jidic
jidic

Reputation: 229

Exception stack trace does not have line numbers

I discovered a strange issue on NetCore that doesn't add the line numbers when you run the application on the server the stacktrace doesn't have line numbers. I create a console application using dotnet new console, added this code:

using System;

namespace bar2
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                throw new InvalidOperationException("some error");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

later I run the app using dotnet run

the code above will print:

System.InvalidOperationException: some error
at bar2.Program.Main(String[] args)

notice that there is no line number if you execute it on linux (the pdb file are available in the folder).

How can I fix this? For production app is really hard to replicate the bug because each time I didn't know the file line number, I see only the error...

NetCore Info .NET Command Line Tools (2.1.200)

Product Information:
 Version:            2.1.200
 Commit SHA-1 hash:  2edba8d7f1

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  16.04
 OS Platform: Linux
 RID:         ubuntu.16.04-x64
 Base Path:   /usr/share/dotnet/sdk/2.1.200/

Host (useful for support):
  Version: 2.1.1
  Commit:  6985b9f684

.NET Core SDKs installed:
  2.1.200 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.7 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

I tried also debug and release mode with "pdb only" setted.

Upvotes: 6

Views: 8652

Answers (1)

Ali Tooshmalani
Ali Tooshmalani

Reputation: 260

  • Go into the Properties window for the project where you want to see stack trace line numbers.

  • Click on the Build "vertical tab".

  • Select "Release" configuration.

  • Uncheck the "Optimize code" parameter to avoid the occasional trace issue with inlined code (this step is not essential).
  • Press the Advanced... button and choose Output -> Debug Info -> pdb-only.
  • Deploy the generated .pdb file with the assembly.

Implemented with the comment below:

  • One other thing to check is in the "Package/Publish Web" section that the "Exclude generated debug symbols" checkbox is also unchecked

For more information look at below link:

Display lines number in Stack Trace for .NET assembly in Release mode

Upvotes: 5

Related Questions