Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$ReturnValue in Watch window doesn't work in VS2015

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?

like image 402
demoncodemonkey Avatar asked Jan 18 '16 15:01

demoncodemonkey


1 Answers

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.

like image 161
Ehsan Sajjad Avatar answered Sep 17 '22 23:09

Ehsan Sajjad