4

I'm using asp.net 3.5

In web.config, I have debug=false and compilerOptions="/debug:pdbonly" to compile with optimizations and still get line numbers in my stack traces. This works for the most part, but I had a bug in a function in my App_Code folder and the stack trace said the error was on a line that couldn't possibly be an error.

I played with my web.config settings a little bit and found that if I set debug=true and compilerOptions=pdbonly, the stack trace says the error is the line directly after the line with the bug. If I remove the compilerOptions=pdbonly, the stack trace reports the correct line as the error.

//the actual bug  (only reported when debug=true and no compiler options set)
var dt = new DateTime(-1,-1,-1);         

//
//...lots of non-buggy code between
//

//the bug according to the stack trace when 
//   debug=false and compilerOptions="/debug:pdbonly"
var ts = TimeSpan.Empty;  

Is there a way to make this work right?

dan
  • 9,712
  • 6
  • 49
  • 62

1 Answers1

4

Compiler optimizations can affect the line numbering reported in the stack trace. You can set the compiler option /optimze- to disable them, then your stack trace line numbers should be correct.

For example: <compiler compilerOptions="/optimze- /debug:pdbonly"/>

arcain
  • 14,920
  • 6
  • 55
  • 75