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.
The java. lang. StackTraceElement. getLineNumber() method returns the line number of the source line containing the execution point represented by this stack trace element.
Simple way, use the Exception. ToString() function, it will return the line after the exception description. You can also check the program debug database as it contains debug info/logs about the whole application.
A trace of the method calls is called a stack trace. The stack trace listing provides a way to follow the call stack to the line number in the method where the exception occurs. The StackTrace property returns the frames of the call stack that originate at the location where the exception was thrown.
The stack trace contains the Exception's type and a message, and a list of all the method calls which were in progress when it was thrown.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With