当我调试我的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 */
}
答案 0 :(得分:2)
您是否正在调试在发布模式下编译的代码?根据编译器使用的优化,变量type
可能实际上并不存在。确认您正在调试Debug编译的代码,然后尝试。 (当我尝试在发布模式下调试时,我的循环没有意义,整个部分都跳了起来。)