CLR debugger and "var"
I am using the CLR Debugger (version 8, from "Visual Studio 2005") to debug C # code. I can execute my code, but for many variables, the debugger won't show me its value. That is, if I type it in the Immediate box or add it to the Watch box, it says "Unable to evaluate expression."
This seems to be a lot for variables var
, but I also see it for parameters and properties. I haven't been able to figure out what a pattern is.
Is there a rule for when it can display the value of a variable? Is there something I need to do in my code or in my build script to make the debugger viewable for variables? Or is there a hidden debugger setting?
a source to share
There is some important information missing from your question. Reverse-engineering: The "var" keyword did not become available until version 3 of C # that ships with Visual Studio 2008. Using the old debugger is a great idea, although it probably isn't a real problem.
Another hint that you are using a standalone debugger and not the one built into Visual Studio. It is very likely that you are debugging the release code, not the code embedded in the Debug config. In this case, getting information about local variables and properties is fine, the JIT compiler will optimize them.
a source to share
The variable must be in scope at the point where you hit the breakpoint. That is, if you break a method, you should see the parameters of that method, local variables and static variables in the containing class.
Regarding var
this "compiler trick" was introduced with Visual Studio 2008, so while you can use it in .NET 2.0 projects, I don't think VS2005 can compile it, so I doubt it can debug it.
a source to share