2

In my error handler code if I put in a breakpoint and hover over the exception I can see the line numbers in the stacktrace. If I store my exception's stacktrace into a string variable to log it, the line numbers are not showing.

This isn't a PDB issue as I'm running debug mode, and the line numbers are there for the exception if I look at it using intellesense... but not if I try to store the value.

If I use the immediate window I get the following with line numbers:

ex.InnerException
{"Object reference not set to an instance of an object."}
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2147467261
    HelpLink: null
    InnerException: null
    Message: "Object reference not set to an instance of an object."
    Source: "TestProject"
    StackTrace: "   at TestProject.Client.GraphAPI.<GetOrphans>d__0.MoveNext() in C:\\source\\TestProject\\TestProject\\Client\\GraphAPI.cs:line 23\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at TestProject.ViewModels.TemplatesViewModel.<FindOrphans>d__31.MoveNext() in C:\\source\\TestProject\\TestProject\\ViewModels\\TemplatesViewModel.cs:line 133"
    TargetSite: {Void MoveNext()}

but if I try to access the StackTrace part of that to save the string I get this:

ex.InnerException.StackTrace
"   at TestProject.Client.GraphAPI.GetOrphans(AuthenticationResult auth, String FolderID, List`1 ExistingIds)\r\n   at TestProject.ViewModels.TemplatesViewModel.FindOrphans()"

Why is the value of StackTrace different when I try to access it than if I'm looking at the entire object?

If it matters these exceptions are generated by a Caliburn.Micro project capturing Coroutine.Completed events for uncaught errors.

Jiale Xue - MSFT
  • 3,560
  • 1
  • 6
  • 21
Brian Heward
  • 524
  • 4
  • 14
  • https://github.com/dotnet/runtime/issues/23837 – Hans Passant Aug 11 '22 at 00:00
  • 1
    @HansPassant I'm not sure what that link has to do with my question. It discusses removing useless stack frames from the StackTrace, but in both his starting and ideal StackTraces the line numbers are still there. – Brian Heward Aug 11 '22 at 00:05
  • It demonstrates pretty well how the stack trace gets cleaned-up from the raw trace. Nobody is going to enjoy having to find the `d__0.MoveNext()` method back in their source code. How the line number info for GetOrphans() got lost is not terribly obvious from the question, merely easy to imagine. Post repro code if you want a better guess. – Hans Passant Aug 11 '22 at 00:39
  • Is there any way to recover the raw trace since that one seems to have line numbers? – Brian Heward Aug 11 '22 at 15:45

0 Answers0