Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Predefined type System.ValueTuple is not defined or imported" after upgrading to .NET 4.7

Tags:

c#

.net

nuget

I'm upgrading an existing solution from .NET 4.6.2 to .NET 4.7. This solution depends on several nuget packages that target .NET 4.6.2 and hence depend on the nuget System.ValueTuple package.

But after upgrading, I'm getting a whole bunch of these build errors:

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

I can't remove the System.ValueTuple package, as suggested in the comments here, because other packages depend on it. (And if I force it, they seem to blow up.)

Any suggestions?

Update 8/8/17

I've figured out that I can remove the System.ValueTuple package, and I can get the solution to compile that way. However, I've got a dozen NuGet packages in the solution which appear to be targeting .NET 4.6.2, and hence require System.ValueTuple as a dependency. I can install those, and then force remove the System.ValueTuple package, but if any of those packages have an update, and I install the update - then the System.ValueTuple package gets installed again, and the system stops building until I remove the package all over again.

In other words, I can make it all work - but it seems awkward and kludgy. Surely there's a better way to approach this?

like image 210
Ken Smith Avatar asked Jul 27 '17 01:07

Ken Smith


2 Answers

Yes, upgrade to System.ValueTuple 4.4.0.

Here is why:

The NuGet package System.ValueTuple provides the ValueTuple types which are required for the C# tuple syntax. In .NET Framework 4.7 we've added the types directly to mscorlib. If you use both, the NuGet package, as well as .NET Framework 4.7 you'll end up seeing the same types multiple times. This results in issues like this one reported on Stack Overflow.

We've updated the NuGet package to type forward the tuple types on .NET Framework 4.7 to mscorlib. This unifies the types and thus allows you to consume other libraries and NuGet packages that depend on System.ValueTuple while still targeting .NET Framework 4.7.

See release notes.

like image 109
Immo Landwerth Avatar answered Oct 13 '22 01:10

Immo Landwerth


In Visual Studion ,NuGet package System.ValueTuple provides the ValueTuple types. So Update System.ValueTuple to latest version v4.4.0. Means Upgrade the System.ValueTuple to higher version then the current or previous one.

like image 34
Varinder Singh Baidwan Avatar answered Oct 13 '22 00:10

Varinder Singh Baidwan