Visual Studio调试器在进行步骤时忽略方法 [英] Visual Studio debugger ignores methods when doing step-into

查看:135
本文介绍了Visual Studio调试器在进行步骤时忽略方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到一些奇怪的行为调试我的C#代码 - 我不能发布我的确切代码,但基本上我有一个部分抽象基类定义一个Execute方法:

I'm seeing some weird behaviour debugging my C# code - I cant post my exact code but essentially I have a partial abstract base class that defines an Execute method:

public abstract partial class MyBase
{
    public abstract void Execute();

    protect static object SomeMethod()
    {
        object aaa = OtherClass.GetObject();
        // etc...
    }
}

我然后有另一个部分类实现这个方法,并在基类上调用一些静态方法:

I then have another partial class which implements this method, and calls some static methods on the base class:

partial abstract class MyParent : MyBase
{
    public void Execute()
    {
        object myobj = SomeMethod();
        // etc...
    }
}

这些部分类是使用xsd.exe从模式生成的部分类的扩展。

Both of these partial classes have are extensions of partial classes generated using xsd.exe from a schema.

我看到的是,如果我尝试进入我的实现的Execute(),Visual Stuido调试器跳过这些方法 - 例如在这种情况下,它会直接转到 OtherClass.GetObject()方法。调用堆栈仍然显示 Execute() OtherClass.GetObject()之间的所有框架,甚至让我设置他们是活动的框架,但是我不能逐行执行代码,除非我在每一行上放置一个断点。

What I'm seeing is that if I attempt to step-into my implementation of Execute(), the Visual Stuido debugger jumps through these methods - for example in this case it would step straight through to the OtherClass.GetObject() method. The call stack still shows all the frames inbetween Execute() and OtherClass.GetObject(), and even lets me set them to be the active frame, however I can't do a line-by-line step through the code unless I place a breakpoint on each and every line.


  • 为什么会这样?

  • 如何解决这个问题,以便我可以正常调试!

推荐答案

xsd.exe通常使用 DebuggerStepThrough 属性来装饰生成的类,这意味着调试器将... ,你得到的照片。

xsd.exe typically decorates generated classes with the DebuggerStepThrough attribute, which means the debugger will .. well, you get the picture.

我以前用一个简单的.vbs脚本来处理这个问题,我在调用xsd.exe(通常作为预构建步骤的一部分)之后调用它:

I've dealt with this in the past with a simple .vbs script that I call after invoking xsd.exe (typically as part of a pre-build step):

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile(WScript.Arguments(0), ForReading)
strText = objFile.ReadAll
objFile.Close

strNewText = Replace(strText, 
    "[System.Diagnostics.DebuggerStepThroughAttribute()]", "")

Set objFile = objFSO.OpenTextFile(WScript.Arguments(0), ForWriting)
objFile.WriteLine strNewText
objFile.Close

生成的文件的名称作为参数,如:

You call it with the name of the generated file as a parameter, as in:

wscript.exe remove_attribute.vbs XsdGeneratedClasses.cs

这篇关于Visual Studio调试器在进行步骤时忽略方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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