Reputation: 229
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
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.
Implemented with the comment below:
For more information look at below link:
Display lines number in Stack Trace for .NET assembly in Release mode
Upvotes: 5