0

I am debugging an WCF project (with debug constant on) and come to this problem. I want to log the line number from the StackTrace of an ecxeption when caught

try
{
    // ...
}
catch (Exception ex)
{
     string message = "Error: " + ex.StackTrace;
     // ...
}

And all I got in the message variable only contains the call stack and method names. What's weird is if I expand the ex variable in the debugger, I can see the full stack trace with line number. Only if I use the property directly will I get the truncated message.

See the screenshot. In the watch window I added 2 variables: ex while expanded, and ex.StackTrace. You can see even in the watch window, when accessing directly the line number is stripped.

So what is causing this behavior?

enter image description here

Lionet Chen
  • 832
  • 11
  • 26
  • I trimmed some empty space from the screenshot to make it easier to see. It was pretty wide. –  Mar 11 '21 at 05:11
  • Does this help you? https://stackoverflow.com/questions/3791696/how-to-get-line-numbers-in-the-stacktrace-of-an-exception-thrown-in-net-to-sh –  Mar 11 '21 at 05:12
  • @Amy Thanks for tidying up for me. You reminded me to check the Debugging information setting and it's on `Full`. When I try again, the line numbers appear normally everywhere - the problem disappeared! Now I can't duplicate it even on a Release build when Debugging info is set to None and a Clean & Rebuild- the line numbers are still there. There must be some messed up settings... – Lionet Chen Mar 11 '21 at 06:35

0 Answers0