Predefined type 'System.ValueTuple´2´ is not defined or imported
Solution 1
For .NET 4.6.2 or lower, .NET Core 1.x, and .NET Standard 1.x you need to install the NuGet package System.ValueTuple
:
Install-Package "System.ValueTuple"
Or using a package reference in VS 2017:
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
.NET Framework 4.7, .NET Core 2.0, and .NET Standard 2.0 include these types.
Solution 2
It's part of the .NET Framework 4.7
.
As long as you don't target the above framework or higher (or .NET Core 2.0
/ .NET Standard 2.0
), you'll need to reference ValueTuple
. Do this by adding the System.ValueTuple
NuGet Package
Solution 3
The ValueTuple types are built into newer frameworks:
- .NET Framework 4.7
- .NET Core 2.0
- Mono 5.0
- .Net Standard 2.0
Until you target one of those newer framework versions, you need to reference the ValueTuple package.
More details at http://blog.monstuff.com/archives/2017/03/valuetuple-availability.html
Solution 4
For Visual Studio Code use the built in Terminal and run:
dotnet add package "System.ValueTuple"
Don't forget to run dotnet restore
afterwards.
Solution 5
I also came accross this issue as I upgraded from .NET 4.6.2 to .NET 4.7.2. Unfortunately, I was not able to remove the package reference to System.ValueTuple
because another NuGet package I use depends on it.
Finally I was able to locate the root cause: There was a .NET 4.6.2 version of mscorlib.dll
lying around in the project folder (output of a publish operation) and MSBuild decided to reference this assembly instead of the official .NET 4.7.2 reference assembly located in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2
.
Due to the fact that System.ValueTuple was introduced in .NET 4.7, MSBuild failed the compilation because it could not find the type in the reference assembly of .NET 4.6.2.
(duplicate of https://stackoverflow.com/a/57777123/128709)
gsharp
If you like StackOverflow favorites and wish improvements read my meta post and vote up.
Updated on July 28, 2022Comments
-
gsharp over 1 year
I've installed Visual Studio 15 Preview 3 and tried to use the new tuple feature
static void Main(string[] args) { var x = DoSomething(); Console.WriteLine(x.x); } static (int x, int y) DoSomething() { return (1, 2); }
When I compile I get the error:
Predefined type 'System.ValueTuple´2´ is not defined or imported
According to the blog post, this features should be "on" by default.
What did I do wrong?
-
gsharp almost 8 yearsThanks. Does it mean it would work with 4.6.2 ? The Debugger still show's x.Item1 x.Item2. Instead of (x.x and x.y) Do you know if that will change?
-
Eli Arbel almost 8 yearsI'm sure it will be included either in 4.6.2 or in 4.6.3. Don't know about the debugger, but since Roslyn is responsible for the expression evaluator, I'd say yes.
-
Eli Arbel almost 8 yearsSeems like it's on their list: github.com/dotnet/roslyn/issues/10945 - Interaction with Debugger
-
Frison Alexander over 7 yearsInstall-Package "System.ValueTuple" -IncludePrerelease
-
binki over 7 yearsWell, it doesn’t seem to be in 4.6.2.
-
Eli over 7 yearsWorks with 4.6.2, still need this package though.
-
HaveSpacesuit about 7 yearsEven with .NET 4.6.2 it seems to still need the System.ValueTuple package.
-
JonathanPeel about 7 yearsI have not been able to get this to work in VS Code.
-
Bidou almost 7 yearsI just tried with .net 4.7 and it didn't work?
System.ValueTuple`2
not found -
Bidou almost 7 yearsI've installed the .net Framework 4.7 and the target pack for Visual Studio. I also selected the version 4.7 in the drop down, but it still doesn't compile.
-
Bidou almost 7 yearsOk I just found the problem: the dll System.ValueTuple was hardcoded in my project file (csproj). Removing this entry from the project file fixed the problem.
-
toddmo almost 7 yearsGood solution, but you might add more details. In my case, System.ValueTuple.dll was still hanging out in my bin folder. Once I deleted that, I was good to go. My language version is at
default
and all is working. -
toddmo almost 7 yearsNote: Don't do this with .Net 4.7
-
toddmo almost 7 years@mrsundquist, yes anything below 4.7
-
Mafii almost 7 yearsWith .NET 4.7, the package is natively included.
-
Shimmy Weitzhandler almost 7 yearsAfter installing the package VS still complaining!
-
Admin almost 7 yearsStill need to install this package before using today (13/07/2017). Thanks!
-
Frederik Struck-Schøning almost 6 yearsJust a note (spent some time on this): if you are using package Microsoft.Net.Compilers in same project, it should be updated to (at least) version 2.0, orelse you will get build/syntax errors. Source/credit: stackoverflow.com/a/41565541/430885.
-
Arghya C over 5 yearsHard coding a fixed file path (or any string) is never a good solution.
-
Alexei S over 5 yearsAdded the package, everything builds, but now unit tests are failing with System.IO.FileLoadException : Could not load file or assembly 'System.ValueTuple