Search code examples
c#async-awaitdecompiler

How to debug auto-generated code?


I am trying to see what goes on in the IAsyncStateMachine at runtime ,and i desperately need to see what variables it has and what it calls.I know you can see the code with the ILSpy ...but i need to debug it.

Is there any method? I need to see what goes on inside the IAsyncStateMachine MoveNext method !

public sealed partial class MethodBuilder<T> : Errand.MethodBuilder {

            public static new MethodBuilder<T> Create() => new MethodBuilder<T>();

            public new void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine {
                this.myStateMachine = stateMachine;
                this.Task = new Task<T>(this);
                stateMachine.MoveNext(); //i have to see the properties of stateMachine and inside this method !!!!!
            }

            public new void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine machine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine {



            }
            public void SetResult(T result) {
                this.Task.isCompleted = true;
                this.Task.result = result;
            }
            public new void SetStateMachine(IAsyncStateMachine stateMachine) => base.SetStateMachine(stateMachine);
            public new void SetException(Exception ex) => base.SetException(ex);
}

Solution

  • From MSDN How to: Debug .NET Framework Source.

    To enable .NET Framework source debugging

    1. On the Tools menu, click Options.

    2. In the Options dialog box, click the Debugging category.

      • In the General box, set Enable .NET Framework source stepping.

      • If you had Just My Code enabled, a warning dialog box tells you that Just My Code is now disabled. Click OK.

    3. If you did not have a symbol cache location set, another warning dialog box tells you that a default symbol cache location is now set. Click OK.

    4. Under the Debugging category, click Symbols.

    5. If you want to change the symbols cache location:

      • Open the Debugging node in the box on the left.

      • Under the Debugging node, click Symbols.

      • Edit the location in Cache symbols from symbol servers to this directory or click Browse to choose a location.

    6. If you want to download symbols immediately, click Load Symbols using above locations.

      This button is not available in design mode.

      If you do not choose to download symbols now, symbols will be downloaded automatically the next time that you start the debugging your program.

    7. Click OK to close the Options dialog box.