11

I am trying to use the new tuple features in C# 7 in an ASP.NET MVC 5 app, using .NET version 4.6.1. and Visual Studio 2017 RC. To do so I referenced this article here: What's new in C# 7, which said to install System.ValueTuple via NuGet. When I did this, the tuple syntax started working for me like in this example code:

public void TupleCaller()
{
   (var valOne, var valTwo) = TupleExample();
}

public (string, string) TupleExample()
{
    return ("Tuple Item One", "Tuple Item Two");
}

However, when I run the app, my views immediately throw this error:

CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

I have tried all of the following:

  1. Adding a reference to System.Runtime Version 4.0 as the error says
  2. Tried what was provided in this C# 7.0 ValueTuple Question/Answer and in this Question/Answer by installing the 2.0 Compilers.
  3. Manually adding a reference to System.Runtime in the view (I think I was just getting a little desperate by that point).

As soon as I uninstall the System.ValueTuple NuGet package and comment out the new Tuple code, everything renders properly in the views like before.

Community
  • 1
  • 1
joshmcode
  • 3,471
  • 1
  • 35
  • 50

2 Answers2

16

I was having the same issue. I added the Microsoft.CodeDom.Providers.DotNetCompilerPlatform Nuget package (v1.0.3) to my project, and it works again!

Alexander Stepaniuk
  • 6,217
  • 4
  • 31
  • 48
Duane Craw
  • 176
  • 1
  • 3
0

I just want to add to the other answers.

Remove System.valuetuple from references. Otherwise it doesn't work and I do not know why. Basically valuetuple is already in 4.7.2 and so if you use visual studio 2019 you're all set.

If you use visual studio 2019 and I did, that's what worked for me. I don't exactly know why. No need for nuget. No need to reference that directly.

enter image description here

user4951
  • 32,206
  • 53
  • 172
  • 282