I'm using the CLR debugger (version 开发者_高级运维8, from "Visual Studio 2005") to debug some C# code. I can step through my code, but for many variables, the debugger won't show me its value. That is, if I type it in the "Immediate" frame or add it to the "Watch" frame, it says "Unable to evaluate the expression.".
It seems to do this a lot for var
variables, but I'm also seeing it for parameters and properties, too. I have not been able to figure out what the pattern is.
Is there a rule for when it can display the value of a variable? Is there something I need to do to my code, or in my build script, to make the debugger able to view variables? Or is there a hidden debugger setting?
There's some crucial info missing from your question. Reverse-engineering: the "var" keyword didn't become available until C# version 3, shipped with Visual Studio 2008. Using an old debugger isn't a great idea, although it probably isn't the real problem.
Another hint is that you use a stand-alone debugger instead of the one that's built into Visual Studio. Making it very likely that you are debugging release code, not code built in the Debug configuration. Not getting info on local variables and properties is quite normal in that case, the JIT compiler optimizes them away.
The variable must be in scope at the point at which you hit a breakpoint. That is, if you break in a method, you should be able to see parameters of that method, local variables, and static variables in the containing class.
With respect to var
, that "compiler trick" was introduced in conjunction with Visual Studio 2008, so although you can use it in .NET 2.0 projects, I don't think VS2005 can compile it, so I doubt it can debug it.
精彩评论