Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet Package for Tuples in C#7 causes an error in my views

Tags:

asp.net

c#-7.0

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.

like image 208
joshmcode Avatar asked Mar 10 '17 00:03

joshmcode


People also ask

How do I add the tuples feature to my project?

To add the Tuples feature, you may want to download and install the NuGet package. Step 1. Right click on the project name in Solution Explorer and select “Manage NuGet Package”. Step 2. Click on the "Browse" tab and type System.ValueTuple in the TextBox. You will see the package name, as shown below. Step 3.

Where can I find C++ packages for NuGet?

The NuGet Gallery on nuget.org is the central package repository used by all package authors and consumers. Since C++ support in NuGet is brand new, there aren’t a lot of packages available in the NuGet Gallery yet. However, the CoApp project has created a few packages from open source libraries which you can use right now to get started.

How to use tuples in C++?

Tuples in C++. 1. get() :- get() is used to access the tuple values and modify them, it accepts the index and tuple name as arguments to access a particular tuple element. 2. make_tuple() :- make_tuple() is used to assign tuple with values. The values passed should be in order with the values declared in tuple.

What NuGet version do I need to use system valuetuple?

System. ValueTuple 4.5.0 Prefix Reserved Requires NuGet 2.12 or higher. For projects that support PackageReference, copy this XML node into the project file to reference the package. The NuGet Team does not provide support for this client. Please contact its maintainers for support.


1 Answers

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!

like image 57
Duane Craw Avatar answered Oct 18 '22 21:10

Duane Craw