Roslyn: Tuples not working in .NET Core Console App

Created on 19 Nov 2016  路  7Comments  路  Source: dotnet/roslyn

Version Used:
Visual Studio 2017 RC

Steps to Reproduce:

  1. Create new .NET Core Console App
  2. Add the following (or similar Method)
static (int sum, int count) Tally(int[] values)
{
    var r = (s: 0, c: 0);

    foreach (var v in values)
    {
        r.s += v; r.c++;
    }

    return r;
}
  1. Add Nuget package System.ValueTuple

Expected Behavior:
Should not have any errors.

Actual Behavior:
Get red squiggles on code:

(int sum, int count)

Get the following error:

Severity Code Description Project File Line Suppression State
Error CS8137 Cannot define a class or member that utilizes tuples because the compiler required type 'System.Runtime.CompilerServices.TupleElementNamesAttribute' cannot be found. Are you missing a reference?

I tried the same steps with a .NET Core Class project and WPF project and appears to work. Did I do something wrong or is this currently a limitation on .NET Core preview tooling?

Thx

Area-Compilers New Language Feature - Tuples

Most helpful comment

"3. Add Nuget package System.ValueTuple"

All 7 comments

Probably nuget System.ValueTuple should be referenced ?

"3. Add Nuget package System.ValueTuple"

I had the same issue, after closing and reopening the solution, the tuple works as expected

@leoniDEV It also appears to work after restarting VS on my side. Thanks for noticing this.

I tried this on RC.2 (VS "Version 15.0.26006.2 D15REL") and did not encounter the problem.
Smells like a project system issue as Sri hinted.
Assigned to Dave, since he already has the related issue..

@jcouv @davkean I also just tried my project with issue from stated above and appears to now work with VS15RC2. Thanks.

Was this page helpful?
0 / 5 - 0 ratings