VS调试器不能按预期工作

时间:2011-09-22 13:07:58

标签: c# visual-studio-2010 debugging

当我调试我的ASP.NET应用程序并在断点处执行时,我无法使用Debug Watches读取type变量。为什么?我收到错误

type    The name 'type' does not exist in the current context   

代码工作正常,问题只在调试时,我无法在调试时读取所有变量。

var converterSubClasses = new List<Type>();
GetClassHierarhy(ref converterSubClasses, converterClass);

foreach (var type in converterSubClasses)
{
  /* break point here */  var classProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
  /* skip code */
}

enter image description here

1 个答案:

答案 0 :(得分:2)

您是否正在调试在发布模式下编译的代码?根据编译器使用的优化,变量type可能实际上并不存在。确认您正在调试Debug编译的代码,然后尝试。 (当我尝试在发布模式下调试时,我的循环没有意义,整个部分都跳了起来。)