18

When I debug my ASP.NET web site code using the Microsoft debug symbol's for .NET .. I keep getting this silly 'result' for most of the variables when I'm debugging .NET framework code (which of course is provided by the Microsoft Symbol Server, which I told VS2008 to grab the info, from)

Cannot obtain value of local or argument 'cookie' as 
it is not available at this instruction pointer, possibly because 
it has been optimized away.

It's like the code I'm using is using optimized, compiled code. If that's the case, can I tell it NOT to optimize? I'm in DEBUG configuration. It's very frustrating because I cannot debug .. cause I can't see/retrieve the values of local variables as I step through the code.

Any clues/thoughts?

Mohammad Dehghan
  • 17,853
  • 3
  • 55
  • 72
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647

5 Answers5

19

Shawn Burke described a method of disabling this on his blog.

First, create a CMD that'll load Visual Studio without JIT optimization.

set COMPLUS_ZapDisable=1
cd /d "%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\ide\"
start devenv.exe
exit

Once in your Visual Studio project, do the following steps:

1) Right click on your project file and choose "Properties"

2) Choose the "Debug" tab and uncheck "Enable the Visual Studio Hosting Process"

3) Launch your application in the debugger.

Cameron MacFarland
  • 70,676
  • 20
  • 104
  • 133
  • You make me excited for a while, I enjoy this during the ASP.NET MVC 3 application debugging and it saved me a lot of time, thank you man – Jahan Zinedine May 18 '11 at 19:48
7

For a normal .Net application you can disable the use of JIT optimizations with an .INI file next to the starting binary. Here's a link to how this is accomplished

http://blogs.msdn.com/jaredpar/archive/2008/08/29/disabling-jit-optimizations-while-debugging.aspx

Debugging ASP.Net is a bit different though and I'm not sure if this will work for you. If you are debugging locally using the light weight web server (cassini) you can apply this trick to Cassini itself. If you are debuggin directly on a web server though inside of IIS I don't know how to get this trick to work but hopefully it will lead you in the right direction.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • Hi JaredPar. I know i'm casting 'resurect dead' upon this thread, but can u give some more info if i'm debugging locally against cassini? – Pure.Krome Apr 10 '09 at 11:14
  • @Pure.Krome, have you tried adding to web.config? See http://support.microsoft.com/kb/815157 – JaredPar Apr 10 '09 at 19:24
3

After a lot of research, I was able to find a way to also make this "COMPLUS_ZapDisable" technique work when attaching to an IIS-hosted application under IIS7/Windows 7 x64.

In my case, I'm using symbols constructed by Reflector Pro, although my guess is that it will also work for the Microsoft symbols that the OP asked about.

The trick is in finding the right place to set that environment variable so that your w3wp.exe is launched with that setting enabled. To do this, add a string key called "COMPLUS_ZAPDISABLE" to your registry at "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment". Set the key value to "1", and that should do the trick. Don't do this on production =)

Kudos to Clive Tong, the author of this post from Red Gate, for pointing me in the right direction.

killthrush
  • 4,859
  • 3
  • 35
  • 38
  • It's worth noting that while the registry hack worked for me, it didn't work *all* the time. After selectively applying @JaredPar's solution I haven't had any more issues. – killthrush Jul 13 '13 at 23:00
1

The .NET framework code is optimized, so you will not be able to view all the variables as they probably don't exist in the optimized code. I assume you are trying to debug inside the .NET framework itself. Nothing much you can do about it unfortunatly.

Robert Wagner
  • 17,515
  • 9
  • 56
  • 72
  • Correct Robert. I'm inside the code that is downloaded from the Microsoft Symbol Server for .NET. For example, the above happens inside SetAuthCookie(..) method, inside System.Web.Security.FormsAuthentication class ... which of course got downloaded from ms's symbol server. – Pure.Krome Nov 17 '08 at 02:48
  • 2
    This is not 100% correct. Most of the errors you are seeing are a result of runtime JIT optimizations. These are suppressable by a .INI file (see my post). There is some opmitazation in the BCL but most of it won't affect debugging if JIT optimazations are suppressed. – JaredPar Nov 17 '08 at 06:51
  • 1
    From the reading you need to put the ini file next to the DLL/EXE that you want to affect. Where do you put it for the BCL libraries? – Robert Wagner Nov 17 '08 at 07:18
0

Finally, this solution worked for me when attaching to the aspnet_wp.exe Visual Studio 2008, .NET framework 2.0 : go into the project properties, into Build tab, Advanced button -> set Output Debug Info to "full". Hope this helps someone.