2

I want to debug Microsoft code on SharePoint site.

I download .NET Reflector Visual Studio Extension so I can step into Microsoft code, but when I try to get the value of some variables - I get the error: "Cannot obtain value of local or argument <this> as it is not available at this instruction pointer, possibly because it has been optimized away."

I try to cancel the optimization, I saw what Cameron MacFarland wrote here, So I created a file with the commands that open VS without JIT optimizations. As for the second action - I do not know how to do it when it comes to a SharePoint application that IIS is running it.

How to achieve this?

EDIT: My question is basically: How to disable code optimization when the code is run by IIS?

Community
  • 1
  • 1
banana
  • 1,186
  • 4
  • 14
  • 26

2 Answers2

2

I posted the answer here, and then saw that it also applied to your specific question.

Long story short, there is a registry setting you can change to make this work. 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"

This original Red Gate article helped me find this trick.

Community
  • 1
  • 1
killthrush
  • 4,859
  • 3
  • 35
  • 38
  • It helped me see the value of some of these variables that were not available. Thank you. – banana Mar 19 '13 at 13:11
  • Now I need it again, I added that key, and still - many variables are not available to me. Maybe there is anything else I should do? – banana Apr 11 '13 at 15:28
  • I would recommend trying some of the additional techniques mentioned in Clive's article, especially the one about using windbg to actually look at the jitting behavior. For me, I was able to consistently debug using only the registry setting so I didn't need to go that far. Odds are if your vars are getting optimized away, it's because of jitting. The trick is to figure out what's triggering it - there may be more that one pathway. One idea that comes to mind is using an isolated app pool to debug your code to make sure that some *other* app isn't causing the optimized code to load. – killthrush Apr 11 '13 at 18:12
  • Also, if you are turning this setting on after having it turned off, you need to make sure that none of the optimized code is left in memory, or it will be reused for your debugging session. I was careful to always run an iisreset after making this registry change in order take care of this. – killthrush Apr 11 '13 at 18:15
  • It's SharePoint, so my Web-application has its own app pool, and I run iisreset after adding the registry key. Still, not everything is available to me. – banana Apr 14 '13 at 05:51
1

The solution I did in the end, Is more or less what JaredPar wrote here:

I created a file that looks like this:

[.NET Framework Debugging Control] 
GenerateTrackingInfo=1 
AllowOptimize=0

And I put it in the GAC, within each folder of dll I wanted to disable its optimization, and named it with the name of the dll, with the extension "ini".

Now, the vast majority of variables are available to me.

Community
  • 1
  • 1
banana
  • 1,186
  • 4
  • 14
  • 26
  • Yes, this worked for me too. It seems to be more reliable than simply using the registry change. – killthrush Jul 01 '13 at 12:39
  • 1
    The name should not contain "dll" in it. For example, if I want to run non-optimized System.Web.dll, then I need a file named System.Web.ini sitting next to it (not System.Web.dll.ini). – Micah Zoltu Dec 03 '14 at 17:46