Visual Studio debugger ignores methods when performing steps

I see some strange behavior debugging my C # code - I can't write my exact code, but essentially I have a partial abstract base class that defines the Execute method:

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

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

      

Then I have another incomplete class that implements this method and calls some static methods in the base class:

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

      

Both of these partial classes are extensions of the partial classes generated by xsd.exe from the schema.

What I see is that if I try to execute my Execute () implementation, the Visual Stuido debugger will jump over those methods - for example, in this case it will jump straight to the method OtherClass.GetObject()

. The call stack still displays all frames between Execute()

and OtherClass.GetObject()

, and even lets me set them as the active frame, however I cannot step through the code step by step unless I put a breakpoint on each line.

  • Why is this?
  • How can I fix this so I can debug normally again ??
+1


source to share


2 answers


xsd.exe usually decorates the generated classes with an attribute DebuggerStepThrough

, which means the debugger will ... well, you get an image.

I've dealt with this in the past with a simple .vbs script that I call after calling xsd.exe (usually as part of the 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, for example:

wscript.exe remove_attribute.vbs XsdGeneratedClasses.cs

+1


source


Also, make sure the Just My Code box is checked to unchechedk, just in case.



0


source







All Articles