locked
Debugging async methods impossible when rewriter is enabled RRS feed

  • Question

  • If I enable the code contracts rewriter, then I'm unable to debug async methods. I should note that I'm on the latest version, 1.4.50910 in VS 2012.

    Here's a simple repro: http://sdrv.ms/SNiYZI

    I suspect it has something to do with the compiler generated classes getting messed up in the PDB. There doesn't need to actually be any contracts for this to occur.

    In the solution, put a breakpoint in the "DoStuff" method near the end of the method. When the breakpoint is hit, look at the locals menu. The local variables aren't there.

    Now, disable the rewriter and try again. The expected locals are present.


    Tuesday, October 9, 2012 10:36 PM

Answers

  • I think Manuel fixed it now. So, please download v1.4.60218.0, give it a try and let us know if it does work

    ciao

    f

    Tuesday, February 19, 2013 10:33 PM

All replies

  • Ping? Any update on this?
    Tuesday, October 30, 2012 12:49 PM
  • I am seeing the same issue in our code. Cannot see locals in async methods with rewriter enabled (Full and ReleaseRequires). A workaround would be very helpfull. We have a lot of Contract. Requires<> code, so not using the rewriter is no an option. 
    Thursday, November 8, 2012 2:31 PM
  • We're suffering from the same issue. The only workaround that we've found is to disable rewriting in Debug build configurations.

    I think it is a showstopper bug that must be solved ASAP.

    Monday, November 12, 2012 1:14 PM
  • Disabling is not an option when using Contract. Requires<>, a fix would be great. Not being able to debug async methods is very blocking.
    Tuesday, November 13, 2012 4:17 PM
  • Happy new year....ping?

    Any progress on resolving this?

    Friday, January 11, 2013 1:23 PM
  • It seems not. :(
    Tuesday, February 5, 2013 9:09 AM
  • It pains me to say it, but next time I have to make changes to the codebase that uses the runtime checking, I'm going to have to remove the contracts in favor of the if/then/throw blocks. It's simply too painful to use the rewriter now, especially with how pervasive async becomes within a codebase.
    Tuesday, February 5, 2013 1:22 PM
  • Agree.

    I'm thinking about my own Contract.Requires / Contract.Ensures / ... implementations that I can easily replace real CC code later.

    Tuesday, February 5, 2013 3:42 PM
  • I've also experienced this.  I did not know it was due to the contract rewriter.
    Tuesday, February 5, 2013 4:54 PM
  • Unfortunately, this is a limitation of the current rewriter. The PDB info for async is not handled properly by our rewriter.

    The only work around at the moment is to disable the rewriter for the debugging session.

    Sorry about that.

    -Manuel


    Cheers, -MaF (Manuel Fahndrich)

    Wednesday, February 13, 2013 6:49 PM
  • I think Manuel fixed it now. So, please download v1.4.60218.0, give it a try and let us know if it does work

    ciao

    f

    Tuesday, February 19, 2013 10:33 PM
  • Whoo!!! Thanks!
    Tuesday, February 19, 2013 11:06 PM
  • Is there perhaps a regression on this?

    I just installed Code Contracts 1.5.60502.11.

    I am unable to see the value of "result" in the debugger in this .Net 4.5 test app when "Perform Runtime Contract Checking" is checked.

    namespace AsynAwaitConsoleApplication
    {
        using System;
        using System.Threading.Tasks;

        class Program
        {
            static void Main(string[] args)
            {
                var x = DoAsyncStuff().Result;
            }

            static async Task<int> DoAsyncStuff()
            {
                var result = await Task.Run(() => 123);
                Console.WriteLine("result: " + result);
                return result;
            }
        }
    }


    See also:
    http://social.msdn.microsoft.com/Forums/en-US/500c963e-d9a8-4934-a849-c7a1ad19babb/bug-regression-cannot-see-locals-in-the-debugger-in-methods-that-contain-a-yield-statement

    • Edited by Wes Day Wednesday, June 19, 2013 4:50 PM Adding link back to related yield statement issue
    Friday, May 24, 2013 1:04 AM
  • I just tried version 1.5.60813.10 and confirmed this issues has been fixed as mentioned in the release notes.
    Monday, September 9, 2013 8:28 PM
  • Thanks for letting us know. Appreciate it.

    -MaF


    Cheers, -MaF (Manuel Fahndrich)

    Monday, September 9, 2013 10:05 PM
  • Tuesday, September 10, 2013 8:00 AM
  • I believe you meant 1.5.60813.10?

    It definitely is working for me.  Make sure and do a full clean/rebuild.

    I verified this specifically resolved the async debugging issue in the sample code in my post above.
    It also resolved the same issue in a few real projects.

    I also just tried a sample yield function and that seems to be working for me also.

        static IEnumerable<int> DoYieldStuff()
        {
            var accumulator = 0;
            for (var i = 1; i < 10; ++i)
            {
                accumulator += i;
                yield return i;
            }

            Console.WriteLine(accumulator);
        }

    Tuesday, September 10, 2013 3:31 PM
  • Ah, I actually meant version 1.5.60502.11  (cut and paste error).

    Unfortunately I can't use version 1.5.60813.10 because it has a bug which causes many false positive code analysis errors in our projects, rendering it unusable.

    Even more unfortunately, nobody for MS has even bothered to reply to my (I thought) carefully written bug report. :(

    See this thread for details.

    Wednesday, September 11, 2013 11:59 AM
  • Granted, the problem with the unused local is now fixed and we will try to push out a new release this week.

    Cheers, -MaF (Manuel Fahndrich)

    Wednesday, September 11, 2013 5:36 PM
  • Thanks, this is all resolved now, thanks to 1.5.60911.10
    Monday, September 16, 2013 12:16 PM