Include file name and line number in stacktrace from ASP.NET kernel

In the full .NET platform, you can include the file name and line number on the stack created from the release build, including debugging information in it and setting Debug info to pdb-only or full . When working in ASP.NET Core and Azure applications, these parameters no longer appear accessible through the user interface or work when adding the generated XML to the project file. When I create a new project and run it in Release mode, the file name and line numbers are not part of stacktrace.

How to include file name and line number in release build in ASP.NET kernel?

Update: steps to recreate!

Add new middleware for registering exceptions:

 app.Use(async (context, next) => { try { await next.Invoke(); } catch (Exception e) { Console.WriteLine(e.ToString()); } }); 

Throw an exception to the default ValuesController :

 [HttpGet] public IEnumerable<string> Get() { throw new Exception(); } 

Create a project (debugging / release doesn't matter). Launch the application using the exe file and press / api / values. Stacktrace does not contain file names and line numbers:

 System.Exception: Exception of type 'System.Exception' was thrown. at WebApplication50.Controllers.ValuesController.Get() at lambda_method(Closure , Object , Object[] ) at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext() 

(I do not want this to turn into a pros / cons message. I know that some people think that including this information is a sin of death, and some not :)

+7
visual-studio asp.net-core .net-core csproj azure-functions
source share
1 answer

To have stack traces with line numbers:

  • Go to project properties
  • build
  • advanced
  • Debug information = complete (be sure to do this in Release Configuration)

Doc: https://docs.microsoft.com/en-us/visualstudio/ide/reference/advanced-build-settings-dialog-box-csharp?view=vs-2017#output

(For some strange reasons, I still have some stack stacks without line numbers, but this is another problem)

0
source share

All Articles