Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the Visual Studio watch window show wrong values for ValueTuples in a collection?

I'm finding that ValueTuples evaluate differently when I access their properties from a collection.

    public static List<Tuple<string, bool>> MyTupleList = new List<Tuple<string, bool>>
    {
        new Tuple<string, bool>("test", true)
    };

    public static List<(string b, bool c)> MyList = new List<(string b, bool c)>
    {
        ("test", true)
    };

Why do these two highlighted lines evaluate differently and how can I change "MyList[0].c" to get the value correctly?

enter image description here

like image 743
Rob Powell Avatar asked Dec 04 '18 12:12

Rob Powell


People also ask

How can you update out of date values in the watch window?

Refresh watch values A refresh icon (circular arrow) might appear in the Watch window when an expression is evaluated. The refresh icon indicates an error or a value that is out of date. To refresh the value, select the refresh icon, or press the spacebar.

How do I show immediate window in Visual Studio?

On the Debug menu, choose Windows > Immediate.


1 Answers

This seems to be a bug in Visual Studio 2017.

There are a few related bugs mentioned on Roslyn's github issue tracker, e.g.:

  • Watch window doesn't handle List<Tuple> properly - which is still open but seems to be fixed (when accessing the value as Item1), see Rango's comment.
  • Debugger can't evaluate list[0].first if T=ValueTuple - moved to the internal Visual Studio bug tracker, since this is not related to the compiler.

Since the issue tracker of Visual Studio is not public, we can only wait and hope that these bugs get fixed.

like image 50
Heinzi Avatar answered Oct 06 '22 00:10

Heinzi