Search code examples
windows-8iis-7.5windows-server-2008-r2stack-traceiis-8.5

Why "enable 32-bit applications" flag breaks line numbers in stack trace


I have ASP .Net Web Application in C# (no MVC or WebForms) compiled in Release mode for AnyCPU, pdb files are enabled and deployed with application.

When enable 32-bit applications on AppPool has the default value of False the stack trace of the exception has correct line numbers.

When the flag is set to True the stack trace has incorrect line numbers.

Just to make it clear the only thing I change is the value for enable 32-bit applications flag in AppPool configuration of my web application.

I have tried this on two machines:

  1. Windows 8 with IIS 8.5.9600.16384
  2. Windows Server 2008 R2 with IIS 7.5.7600.16385

In my particular case it is OK to just reconfigure AppPool (we have already migrated from x86 to AnyCPU and this obsolete configuration is just a mistake), but I am still interested why does this happen? (may be there is some bug in IIS, I was not able to find this behavior mentioned anywhere).

Update: it seems I have figured it out, but this is a temporary reprieve:

  1. The problems is almost certainly due to code optimization (I have written code in such a way, that rules out other options: jitter reorders functions. This is not a compiler because I do not recompile application between tests).
  2. Most of the optimization is done by jitter, and x86 optimizations are more aggressive than x64 optimizations, thus the difference in resulting code. When Microsoft decides to make x64 optimizations more agressive lines will be broken.

Solution

  • So the answer seems to be:

    1. There are basically two steps of optimization in C#: a compilter (csc.exe, when C# code is translated into IL) and a jitter (when IL is translated in machine code). Jitter does not most of the optimizations (article). Also there is a great post by Eric Lippert about which optimization you might expect.

    2. x86 and x64 jitters do different optimizations (CLR via C# Fourth Edition by Jeffrey Richter, Part V Threading, section Volatile Constructs, page 764)

    Thus you can get correct line numbers in x64 (because jitter does not optimize code that aggressively) and x86 (that is more mature).

    Summary: I have not found a way to work around it.