Latet beta c# 7 tupels are not working


With Tuples samples I am getting following error.

CS8179 Predefined type 'System.ValueTuple`2' is not defined or imported


  • edited November 2016
    Run the following query in C# Statements mode:

    Process.Start (Path.GetDirectoryName (GetType().Assembly.Location));

    and then click on the folder in explorer (it might be behind LINQPad).

    Do you see any subdirectories starting with 'shadow'? And if you open one of them, is there a file present called 'System.ValueType.dll'?
  • Can you try a couple of things and tell me if it makes any difference.

    First, explicitly add a reference to that file.

    If that doesn't help, try running the following query, which includes a reference to the System.ValueTuple nuget package:

  • That didn't help either.
  • Is this happening on just one machine? Can anyone else repro it?
  • I can repo this; however, I have only seen this behavior on one of several machines. The machine that has the problem is using Windows 10 Insider Build (slow track), Visual Studio 2017 Ent. RC, Visual Studio 2015.3 and several dotnet core sdks (1.0.0-preview3-004056, 1.0.0-preview2-003131, 1.0.0-preview2-003121, 1.0.0-preview2-1-003177).

    ...this isn't a production machine ;-)
  • If it helps, the CS8179 error is visible in Intellisense; i.e. before the code is actually compiled and ran. There's red squiggles...
  • On the machine that I am experiencing the "System.TupleValue'2 is not defined or imported", I am also getting that same error message inside the newest version of Visual Studio 2017 RC( v15.0.26009.0). I don't know enough about the Roslyn compiler services but since I'm experiencing shared behavior between the two applications, I'm guessing the problem may be due to something like that. May not be anything to do with Roslyn....maybe completely a Windows 10 insider build issue....
  • edited January 2017
    Every time I start LinqPad, System.ValueTuple.dll gets automatically added under %AppData%\..\Local\Temp\LINQPad5\System.ValueTuple. If I delete this folder, things start to work as expected. I have VS 2017 RC installed.

    When before deleting the folder, I tried this:

    System.Runtime.CompilerServices.TupleElementNamesAttribute namesAttr;

    I got this error:

    CS0433 The type 'TupleElementNamesAttribute' exists in both 'System.ValueTuple, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' and 'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    which led me to look for System.ValueTuple.dll and in turn to delete the folder under temp.

    "Tuples" linqpad sample mentions in the end:

    // Tuples rely on a new type called System.ValueTuple, in the NuGet package of the same name.
    // LINQPad includes this automatically, so you don't have to import anything.

    After deleting the folder, I was always getting a warning that %AppData%\..\Local\Temp\LINQPad5\System.ValueTuple\System.ValueTuple.dll does not exist, although things worked as expected. To avoid the warning and while waiting until Joe fixes this, I compiled an empty dll named System.ValueTuple.dll, which I use to overwrite the one LP writes in this folder when it starts.
    The overwrite is conveniently done by a little LinqPad script:

    var dummy = Environment.ExpandEnvironmentVariables(@%AppData%\..\Local\Temp\LINQPad5\System.ValueTuple.dll);
    var extra = Environment.ExpandEnvironmentVariables(@%AppData%\..\Local\Temp\LINQPad5\System.ValueTuple\System.ValueTuple.dll);
    File.Copy(dummy, extra, true);

    It seems to me that when a system already has all the necessary, LINQPad should not try to add this reference automatically.
  • CS0433 The type 'TupleElementNamesAttribute' exists in both 'System.ValueTuple, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' and 'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    I don't understand how that attribute can exist in mscorlib. The mscorlib assembly is part of CLR 4 which was released in 2010.

    The types for value tuples are supposed to come from the System.ValueType.dll assembly, which is available on NuGet. If you add a reference to this assembly, LINQPad will not add its own automatic reference to System.ValueType.

    Is there something I'm missing?
  • Using ILSpy, I can confirm that the mscorlib.dll that I have on my problematic machine includes System.ValueTuple in mscorlib.

    - Windows 10 Enterprise Insider Preview. Build 14986.rs_prerelease.161202-1928.
    - Visual Studio Enterprise 2017RC/15.0.0-RC.4+26206.0
    - dotnet --version := 1.0.0-rc4-004771
    - mscorlib ilspy header:
    // C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll
    // mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089
    // ...
    // [assembly: AssemblyFileVersion("4.6.2012.0")]
  • edited March 2017
    I'm also running a Windows 10 insider's build (15061.0) which has the problem. Perhaps it is related?

    Also, after removing the offending folder as I said before, and running this:

    var namedTuple = (word: "three", number: 3);

    I get this dumped:

    (three, 3)
    Item1 three
    Item2 3

    which obviously has another problem, as the names were lost.
  • Just to be sure, can you please confirm the result of the following query:

    typeof (int).Assembly.GetType ("System.ValueTuple") == null

  • I thought that I read that named tuple values are only available during compile-time. The names are not available at runtime and through reflection.
  • edited March 2017
    To confirm,

    typeof (int).Assembly.GetType ("System.ValueTuple") == null


    There has been an update to the Windows 10 Insider Slow ring build in the last few days; mscorlib(C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll) is now at [assembly: AssemblyFileVersion("4.7.2046.0")].

    Hope this helps!

    [edit] P.S. Running Visual Studio 2017 Enterprise RTM.
  • Try RC4:

    This new build checks whether mscorlib contains System.ValueType, and if so, automatically removes the automatic reference to System.ValueType.dll.
  • Perfect! All three Tuple samples (from the New features folder) executed perfectly.

    Thank you very much,
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!