Sometime back I found myself trying to remotely debug a program thru visual studio, and while trying to access the value of one of the variables I got a message saying “Cannot evaluate expression because the code of the current method is optimized”… turns out that there are compilation flags that instruct the JIT to optimize the code (usually on release builds) and thus some variables will not be available during debugging. You may instruct the JIT not to optimize the code by doing the following:
Let’s say that you have:
Then you will create a new text file with the same name as the dll you are trying to debug but with “ini” extension, example:
Open this file with Notepad and insert the following text in it:
[.NET Framework Debugging Control]
This will override the optimization flag and then you will be able to see all the variable values
Please note that this is not intended for production usage!