1

I'm confused by a callstack a customer sent me. The customer's version is, of course, a release build, but the line number of the exception just doesn't make sense.

Just now I noticed that there is a #if DEBUG...#endif block above the specified line number.

Is this block removed by/for the compiler, resulting in a different line number between debug and release builds, if there is a #if DEBUG...#endif block somewhere in the code aobve the specified location?

mike
  • 1,627
  • 1
  • 14
  • 37
  • 1
    release builds are optimized by compiler, I wouldn't expect the same line numbers with debug build – Pavel Anikhouski Mar 24 '20 at 16:06
  • 1
    Line number info in the Release build cannot be reliable, the jitter optimizer [moves code around](https://stackoverflow.com/a/4045073/17034). That's why the default build setting omits line numbers from the PDB file. You changed that setting, all you can do is not trust your eyes too much. – Hans Passant Mar 24 '20 at 16:07
  • 1
    The statements inside an `#if DEBUG` conditional compilation block will not be compiled (not included in the IL) if the DEBUG conditional compilation switch is not specified. Release build configurations normally do not specify this switch. But the line numbers will still be reported correctly. (Tested). (does the pdb file on your customer's server is the output of the same build with the assembly?) – Oguz Ozgul Mar 24 '20 at 16:34
  • @oguz yes, pdb files match – mike Mar 24 '20 at 18:46

1 Answers1

1

As further testing showed and the links and comments above indicated: line numbers may differ for various JIT optimization reasons, but not simply because of a #if...#endif block.

mike
  • 1,627
  • 1
  • 14
  • 37