Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "Tuple element name is inferred. Please use language version 7.1 or greater to access an element by its inferred name."

We have the following code that has been working fine in our UWP app until today after we updated Visual Studio 2017 to the latest 15.3.

private void Test()
{
    var groups = new List<(Guid key, IList<(string, bool)> items)>();

    var items = new List<(string, bool)>
    {
        ("a", true),
        ("b", false),
        ("c", false)
    };
    var group = (Guid.NewGuid(), items);

    groups.Add(group);
}

There is no error message but this in the output window

Tuple element name 'items' is inferred. Please use language version 7.1 or greater to access an element by its inferred name.

Any idea why and how to fix this?

like image 515
Jessica Avatar asked Aug 14 '17 23:08

Jessica


2 Answers

Project->Properties->Build->Advanced->Language Version->C# latest Minor Version

like image 125
John Stewien Avatar answered Oct 15 '22 16:10

John Stewien


Looks like this is a breaking change in C# 7.1. (as pointed out by @JulienCouvreur, this is actually a bug, but the workaround below should still work though).


Workaround

Try giving a name (e.g. use the same name items from IList<(string, bool)> items to be consistent) explicitly to items (i.e. the list instance).

var group = (Guid.NewGuid(), items: items);
like image 11
Justin XL Avatar answered Oct 15 '22 16:10

Justin XL