$ReturnValue in Watch window doesn't work in VS2015
Asked Answered
P

3

10

In VS2013 we could view the return value of a method by examining a Watch window entry called $ReturnValue. This doesn't seem to work in VS2015.

e.g. I made a new console app, containing the following code:

using System;

namespace ReturnInspector
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Number: {0}", Method1());
        }

        public static int Method1()
        {
            return Method2(1000);          //A
        }                                  //B

        private static int Method2(int i)
        {
            return i + 42;
        }
    }
}

If I put a breakpoint on line //A, then once it breaks, F10 to step to line //B, the $ReturnValue item in the Watch window shows "1042" in VS2013, but in VS2015 it shows this:

error CS0103: The name '$ReturnValue' does not exist in the current context

Note that the Autos and Locals windows correctly say this:

ReturnInspector.Program.Method2 returned    1042

Does anyone know whether $ReturnValue in the Watch window feature was dropped in VS2015?

Pappose answered 18/1, 2016 at 15:32 Comment(0)
B
10

Make sure that you have in Tools >> Options >> Debugging >> Use the legacy C# and VB expression evaluators option checked.

From MSDN:

You must have the legacy expression evaluators turned on for $ReturnValue to be recognized (Tools / Options / Debugging / Use the legacy C# and VB expression evaluators). Otherwise, you can use $ReturnValue1.

Banyan answered 18/1, 2016 at 15:34 Comment(7)
What's the different between single and double > ? @PatrickHofmanBanyan
You created a block quote inside another block quote. That gives layout issues sometimes and just looks bad.Rockies
Why was this deprecated/not on by default?Kaceykachina
"Use the legacy C# and VB expression evaluators" option is grey on my VS 2017, not possible to activate it. Any idea?Gley
@Gley Stop debugging session before changing the optionTherrien
Why should we turn on legacy options? Is there a less legacy/depreciated way of doing this?Malebranche
@RichardGarside Right?? Looks like in VS 2022 it's $returnvalue and becomes set immediately after stepping out of the method.Dilution
D
1

In Visual Studio 2022, use $returnvalue in the Watch window. It should get set immediately after stepping out of the method.

Editorial: It's worth considering assigning your results to a variable as a habit before returning to avoid the need for this.

Dilution answered 7/8, 2024 at 20:47 Comment(0)
N
0

In VS2019 Community it works with $ReturnValue1

Nahtanha answered 10/12, 2019 at 11:17 Comment(1)
$ReturnValue1 is to be used in case legacy expression evaluators are turned off (Tools / Options / Debugging / Use the legacy C# and VB expression evaluators). See learn.microsoft.com/en-us/previous-versions/dn323257(v=vs.140)Ambrose

© 2022 - 2025 — McMap. All rights reserved.