6

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.

jidic
  • 229
  • 2
  • 9
  • 1
    Are you in release- or in debug-mode? – MakePeaceGreatAgain Jun 25 '18 at 07:42
  • No repro with 2.1. Which version of .NET Core did you use? Reminder, the long-term support version is 2.1. – Panagiotis Kanavos Jun 25 '18 at 07:43
  • No repro even with `dotnet run -c Release`. – Panagiotis Kanavos Jun 25 '18 at 07:45
  • @HimBromBeere I tried both, and in release mode I set "pdb only" but same result. Version of NetCore: 2.0 with console app – jidic Jun 25 '18 at 07:48
  • @jidic you tried what? What version of .NET Core did you use? I can't reproduce what you describe either in debug or release mode. No repro with a project created by Visual Studio or one created with `dotnet new console`. – Panagiotis Kanavos Jun 25 '18 at 07:49
  • @jidic post the OS version you used as well. This can't be reproduced on *Windows*. Post the results of `dotnet --info` too, except the long SDK/runtimes list. This will show the actual OS and Core versions – Panagiotis Kanavos Jun 25 '18 at 08:27
  • @PanagiotisKanavos Please chek my update – jidic Jun 25 '18 at 08:59
  • @jidic no repro under [Windows Subsystem on Linux](https://learn.microsoft.com/en-us/windows/wsl/install-win10) with Ubuntu 16.04 either, running .NET Core 2.1. I did find [this issue on the .NET Core repo](https://github.com/dotnet/corefx/issues/21079) that seems relevant though. Looks like it's specific to 2.0 on some OSs. Try updating to Core 2.1. You'll have to anyway, 2.0 isn't LTS and [reaches End-Of-Life this October](https://blogs.msdn.microsoft.com/dotnet/2018/06/20/net-core-2-0-will-reach-end-of-life-on-september-1-2018/). 2.1 is the LTS version. – Panagiotis Kanavos Jun 25 '18 at 09:01
  • @PanagiotisKanavos I updated already, I'm trying this in production right now, I'm waiting for an error in production, let's see what happen – jidic Jun 25 '18 at 09:16
  • "pdb only" was a pretty clunky choice for a name to describe the PDB you'd get. They should have picked "stripped pdb", all info about source files and line numbers is stripped from the file. The typical release build choice, the jitter optimizer makes line number info unreliable because it moves code around. – Hans Passant Jun 25 '18 at 09:48
  • @HansPassant so if I understood you, if I choose pdb only I can't get the line number? Which one should I select for have a complete stack details? – jidic Jun 25 '18 at 10:10
  • The traditional choice is "full", but you are doing this on Linux. Backgrounder on the new portable format [is here](https://github.com/dotnet/core/blob/master/Documentation/diagnostics/portable_pdb.md). – Hans Passant Jun 25 '18 at 10:19
  • @HansPassant I actually trying the latest version of the framework 2.1, that have a fix on this field, if this won't work I'll compile the release as "full", thanks for this – jidic Jun 25 '18 at 10:25

1 Answers1

4
  • 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

Ali Tooshmalani
  • 241
  • 2
  • 7
  • Unfortunately I already did this, I'm trying to update to the last version 2.1 on my ubuntu server for see if this version doesn't have this issue – jidic Jun 25 '18 at 08:17
  • 2
    @jidic you forgot to say what OS you used. That matters *a lot*. As I said, I couldn't reproduce what you wrote, on *Windows*. You probably can't fix this problem by changing project properties if the *runtime* doesn't support them. – Panagiotis Kanavos Jun 25 '18 at 08:24