locked
VS RC 2012 Debugger not recognizing result of result from "await" call RRS feed

  • Question

  • I have an app that uses the new TAP/async stuff pretty heavily. I have several GUI event handlers whose last line ends in a call to a method with "await", like this:

    String s = await MyTaskReturningFunction(...)

    My problem is that I'm frequently having trouble using the debugger to examine "s". Here's what I've tried:

    If the above statement is the last line in the method, I put a breakpoint on the closing brace of the method. When the debugger stops there, "s" is not recognized by the debugger (but other local variables are)

    I can add a "placeholder" line of code after the above line, like "Int32 j = 5" and put a breakpoint on this. Sometimes, when I run the code, the breakpoint gets mysteriously pushed down to the next line of code (sometimes into the next method!), or, if I get lucky and the debugger does stop on "j = 5", "s" is not recognized by the debugger.

    This does not always happen but it happens frequently with this application.

    Is this a know problem and/or are there things I could check to get to the bottom of this?

    THanks

    Michael

    Friday, September 21, 2012 7:59 PM

All replies

  • Hi Michael,

    Thank you for visiting the MSDN forum.

    String s = await MyTaskReturningFunction(...)

    Do you mean that the breakpoint isn’t hit when you add it to the above line code?

      • If the code isn’t used by your app, it will generate this issue, so if you remove this line code, does your app work well? If it worked normally, I’m afraid that this line code isn’t used.
      • If it generated the error when you remove this line code. Like this FAQ “How do I troubleshoot “the breakpoint was not hit” issue?

    (1). Make sure the latest SPs/hotfixes are downloaded and installed properly

    (2). The following project are configured correctly
    in ASP.NET project, ASP.NET debugger is checked
    in SQL Server project, SQL/CLR Debugging is allowed on the data connection
    in Silverlight project, Silverlight debugger is checked

    (3). Make sure Visual Studio is in Debug mode since code in debug mode is not optimized

    (4). Open Processes window (Debug -> Windows -> Processes), make sure the current debugging type is expected type

    If I have misunderstood anything, please make free feel to let me know.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, September 25, 2012 2:30 AM
  • Hi there

    Thanks for your reply.

    I think I may have mis-communicated what I'm seeing. Here's a better example:

    String s = await MyTaskReturningFunction(...) String t = s;
    }

    In the above scenario, I put a break point on the last line of the event handler, "String t = s". The debugger stops there as it should.  But the debugger does not recognize symbol "s" at that point.  The code seems to be working (t is being assigned to s and I can then examine t, but s cannot be examined.. the debugger simply doesn't "see" s)

    Thursday, September 27, 2012 1:53 PM
  • Hi Michael,

    Glad to receive your reply.

    but s cannot be examined. the debugger simply doesn't "see" s

    Based on your description, it seems that the breakpoint it hit, but I’m not very sure what you mean about “the debugger simply doesn't "see" s”, could you share us a screen shot about the result you get?

    In addition, if you want to check a variable, you could check it in the Local/Watch window after the breakpoint is hit, and then check the string value.

    If possible, you could share us a simple app, and then share us a screen shot about the result you get, and then we will try to debug it in out PC.

    Please also attach your Visual Studio project, you can upload it to the sky driver, and then share the download link in your post.

    Have a nice weekend,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Friday, September 28, 2012 7:18 AM
  • Interesting, that VS2012 RC seems to have also problems with async and pdb (locals).
    Only doing some tests with VS2010 and 'Visual Studio Async CTP (Version 3)', encountering problems with 'Watch' of return-value
    ("The name 'xxx' does not exist in the current context"),
    my workaround was splitting function

    Task<string> stringTask = MyTaskReturningFunction();         
    string result = await stringTask;

    and evaluating 'Result' property of 'stringTask' in 'Watch Window' - but as I said, it was only some testing 'Technology Preview' Async CTP (Version 3).

    No warranty - Vista32
    With kind regards

    Besides: I think there is a nice example at
    http://msdn.microsoft.com/en-us/library/hh524395.aspx
    which, with some minor changes may be used for testing.


    Friday, September 28, 2012 10:15 AM
  • Well, it's a huge project, I don't think you want me to upload it :)

    When I say the debugger doesn't see "s", I mean that:

    1. If I try to set a watch on S while sitting at the breakpoint, it says something like "symbol not recognized".
    2. If I try to get fly-over evaluation, put putting my mouse pointer on s while sitting at a breakpoint, nothing happens. (I can put my mouse cursor over any other local symbol and they are recognized)

    Michael

    Friday, September 28, 2012 8:51 PM
  • I have the same issue as well. When executing simple code like:

    HttpResponseMessage response = await _httpClient.PostAsync(uri, content);
    response.EnsureSuccessStatusCode();

    The debugger correctly stops on the second line but it is not able to resolve the response. Both intermediate and watch windows show:

    The name 'response' does not exist in the current context

    I'm running VS 2012 Professional RTM and this code is executed inside Portable Class Library targeted to .NET 4.5 and Windows Store Apps. I had to disable Just My Code in debugger settings to be even able to debug portable class library in the same solution.

    Workaround provided by @MaybeCompletelyW doesn't work for me.

    Edit: Debugging now works with Just My Code enabled but the issue with not recognized variables prevails. I tried to reproduce the issue in simple app but it worked there.


    Saturday, September 29, 2012 9:59 PM
  • Yes, I also tried reproducing it in a simple app and had no problems. Somehow the debugger is getting confused by I can't nail it down any more than that..
    Monday, October 1, 2012 1:58 PM
  • Thanks for Ladislav and MaybeCompletelyW’s help.

    Hi Michael,

    I also tried reproducing it in a simple app and had no problems.

    So the simple app worked normally, just this specific app has this issue, am I right?

    If I try to set a watch on S while sitting at the breakpoint, it says something like "symbol not recognized".

    Could you share us a screen shot about the error message in the watch window? Did you get any warning or error message in the Output window? If have, please share it to us, maybe we could find useful information.

    In addition, if possible, check the Modules Window, and check the Symbols downloaded.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, October 2, 2012 3:21 AM
  • Veloz,

    Are you using any type of IL Weaving in your project? I have had similar issues and have found that projects that are configured to use Notify Property Weaver experience your described problem when debugging in Visual Studio 2012. 

    The below code says the variable "test" is out of context when debugging with Notify Property Weaver configured. But once I disable Notify Property Weaver the variable "test" can be displayed

        [TestClass]
        public class TicketViewModelTest
        {
            [TestMethod]
            public void TestAsynch()
            {
                AsyncDebuggerTest();
            }

            public async void AsyncDebuggerTest()
            {
                var test = await getTestString();
                var test2 = test+test;
            }

            private async Task<string> getTestString()
            {
                return "test";
            }
        }

    • Proposed as answer by antbj Tuesday, March 12, 2013 2:14 PM
    Tuesday, October 23, 2012 5:55 PM
  • @adroach1: That is interesting point. I think my large project was using Code contracts.
    Wednesday, November 21, 2012 1:18 PM
  • I have a problem with Visual Studio Professional 2012, where I get the "The name 'xxx' does not exist in the current context" error when trying to view the value of variables within an async task. After seeing Ladislav's comment I turned off the Perform Realtime Contract Checking in Code Contracts and now I can see the value of all variables when debugging. I have the latest version of Code Contracts (Release 1.4.51019.0).

    Thank you

    Friday, November 30, 2012 11:33 AM
  • Interestingly, I have another case of the debugger not "seeing" symbols, and it's not related to async at all.

    See: http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/188d9bdd-1a39-41cb-a427-f72c5eba0c79

    Don't know if both of my threads are the same "cause", but the symptoms are the same.. In some cases, variables are just "not seen" by the debugger. Sometimes adding more lines of code will "fix this". For example, if the debugger can't see a symbol named XYZ, I may declare another variable right after that named ABC (which is type compatible) and assign ABC = XYZ. Then the debugger can see *both* of these.

    Very strange. I think we have a bonafide bug here..

    Michael

    Wednesday, December 5, 2012 7:52 PM
  • @adroach1: I had the same issue, and it was due to the Fody extension (successor to Notify Property Weaver). Thanks!
    Tuesday, March 12, 2013 2:15 PM