DebuggerStep被忽略 [英] DebuggerStepThrough being ignored

查看:164
本文介绍了DebuggerStep被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我注意到Visual Studio 2010调试器不断跳入这个标有 [DebuggerStepThrough] 属性的方法。





callstack看起来像这样:


  1. Page.OnLoad调用一个方法 IsSubclassOfGeneric 类标记为 [DebuggerStepThrough]

  2. IsSubclassOfGeneric 调用 GetHierarchy 将lambda表达式传递给 System.Linq.Enumerable.Any 扩展名。

  3. Visual Studio进入如上所示的方法。

我刚刚用foreach循环替换了Linq调用,如下所示,无效:





这是一个烦恼,因为这种方法是调用很简单,我不明白为什么属性被忽略。

解决方案

尝试这个简单的控制台应用程序,放置断点在指示的行上,运行调试器,并在第一个断点处,按步骤(F11)。应该错过第二个断点。其他的,如果可能是视觉工作室设置/扩展搞砸了事情。

  using System; 
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Diagnostics;

命名空间tmp {
类程序{
static void Main(string [] args){
IEnumerable< Type> types = typeof(System.IO.IOException).GetHierarchy(typeof(System.Exception)); // break point here
int i = 0;
}
}
static class Ext {
// [DebuggerStepThrough]
// [DebuggerNonUserCode]
// [DebuggerStepperBoundary]
public静态IEnumerable< Type> GetHierarchy(此类型类型,类型限制){
if(type == null){// break point here
throw new Exception();
}
do {
yield return type;
if(type == limit){
yield break;
}
} while((type = type.BaseType)!= null);
}

[DebuggerStepThrough]
public static IEnumerable< Type> GetHierarchy2(此类型类型,类型限制){
if(type == null){// break point here
throw new Exception();
}
IList< Type> types = new List< Type>();
do {
types.Add(type);
if(type == limit){
break;
}
} while((type = type.BaseType)!= null);
返回类型;
}
}
}

strong>



其实我认为这与yield语句有关。如果我尝试构建一个列表(GetHierarchy2),我没有问题的DebuggerStepThrough属性


I have noticed lately that the Visual Studio 2010 debugger keeps jumping into this method that is marked with the [DebuggerStepThrough] attribute.

The callstack looks something like this:

  1. Page.OnLoad calls a method IsSubclassOfGeneric in a class marked as [DebuggerStepThrough].
  2. IsSubclassOfGeneric calls GetHierarchy as shown, passing a lambda expression to the System.Linq.Enumerable.Any extension.
  3. Visual Studio steps into the method as shown above.

I have just replaced the Linq call with a foreach loop as below, to no avail:

This is a bit of an annoyance, since this method is called pretty frequently, and I do not understand why the attribute is being ignored.

解决方案

Try this simple console application, put break points on the lines indicated, run the debugger and on the first break point, press step into (F11). It should miss the second break point. Otherwsie if might be a visual studio setting/extension messing things up.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace tmp {
    class Program {
        static void Main(string[] args) {
            IEnumerable<Type> types = typeof(System.IO.IOException).GetHierarchy(typeof(System.Exception)); //break point here
            int i = 0;
        }
    }
    static class Ext {
        //[DebuggerStepThrough]
        //[DebuggerNonUserCode]
        //[DebuggerStepperBoundary]
        public static IEnumerable<Type> GetHierarchy(this Type type, Type limit) {
            if (type == null) { //break point here
                throw new Exception();
            }
            do {
                yield return type;
                if (type == limit) {
                    yield break;
                }
            } while ((type = type.BaseType) != null);
        }

        [DebuggerStepThrough]
        public static IEnumerable<Type> GetHierarchy2(this Type type, Type limit) {
            if (type == null) { //break point here
                throw new Exception();
            }
            IList<Type> types = new List<Type>();
            do {
                types.Add(type);
                if (type == limit) {
                    break;
                }
            } while ((type = type.BaseType) != null);
            return types;
        }
    }
}

EDIT

Actually i think it has something to do with the yield statement. If i try building a list (GetHierarchy2), i have no problem with the DebuggerStepThrough attribute

这篇关于DebuggerStep被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆