views:

35

answers:

2

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...
    }
}

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

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.

  • Why is this?
  • How can I fix it so I can debug normally again!?
+1  A: 

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

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

Ben M
A: 

Also, make sure the Just My Code checkbox is unchechedk, just in case.

Omer Raviv