pamidur / aspect-injector

AOP framework for .NET (c#, vb, etc)
Apache License 2.0
745 stars 112 forks source link

Local variables in async methods are not visible in the VS debugger #71

Closed pberggreen closed 5 years ago

pberggreen commented 6 years ago

When I am debugging an async method in visual studio and I am trying to see the value of a local variable, I get the error message: "error CS0103: The name 'x' does not exist in the current context". I am using aspect-injector version 1.0.1. I am primarily having this problem in web api controllers, but I can reproduce the problem in the following console app:

class Program
    {
        private static void TestMethod() => Task.Run(() =>
        {
            var x = 1; 
            Console.WriteLine(x);
        });

        private static void AsyncTestMethod() => Task.Run(async () =>
        {
            var x = 2;
            Console.WriteLine(x);
        });

        static void Main(string[] args)
        {
            TestMethod();
            AsyncTestMethod();
            Console.ReadLine();
        }
}

If I put a breakpoint in Console.WriteLine(x) in TestMethod, I can see the value of x in the debugger. But when I do the same thing in AsyncTestMethod, I get the error message, and I cannot see the value of x. The only difference between TestMethod and AsyncTestMethod is that AsyncTestMethod is running the lambda expression async. I hope that there is a solution to this problem - It has been driving me crazy.

pamidur commented 6 years ago

Thanks for report, I'll be looking into it

pamidur commented 5 years ago

Should be fixed in 2.0.0-beta1