Predefined Type 'System.Valuetuple'2' Is Not Defined or Imported

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

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.

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

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.

Xamarin - Multi-targetting - 'System.ValueTuple`2' is declared in multiple referenced

I don't know which assemblies the conflict occurred in.
However, I realized I had not myself added the ValueTuple nuget package so I explicitly did and the error went away.

ternary operator || Predefined type 'System.ValueTuple`3' is not defined or imported

The problem is not the conditional operator, both sides are of type ValueTuple`3. So the conditional operator ? returns a ValueTuple`3.

But no overload of Color.FromArgb takes a ValueTuple`3 as argument.

The compiler does not deconstruct the ValueTuple`3 into the three int arguments for the overload you intend to use.

C# Interactive not recognizing ValueTuple reference

Remove /r:System.ValueTuple.dll from

C:\Program Files (x86)\Microsoft Visual Studio\2017\<edition>\Common7\IDE\CommonExtensions\Microsoft\ManagedLanguages\VBCSharp\InteractiveComponents\CSharpInteractive.rsp

for Visual Studio 2017 and

C:\Program Files (x86)\Microsoft Visual Studio\2017\<edition>\MSBuild\15.0\Bin\Roslyn\csi.rsp

for the command line tool (csi.exe)

Roslyn future branch cannot use C# 7 feature tuples - Error CS0518 Predefined type 'System.ValueTuple`2

I solved this issue by manually including the System.ValueTuple class from the roslyn github repository

The model item passed into the ViewDataDictionary is of type 'System.ValueTuple`2

You are creating a ValueTuple<List<Comment>, int?> when the view is expecting a ValueTuple<IList<Comment>, int?> (note the List vs IList) and the compiler sees these as different types. Use the correct tuple type:

@Html.Partial("_ShowComments", ValueTuple.Create<IList<Comment>, int?>(Model,null))

Or, in my opinion, the cleaner syntax:

@Html.Partial("_ShowComments", ((IList<Comment>)Model,null))

Or, my preferred solution, create a proper class to hold the values:

public class ShowCommentsModel
{
public IList<Comment> Comments { get; set; }
public int? ParentId { get; set; }
}

And switch the view to use:

@model ShowCommentsModel


Related Topics



Leave a reply



Submit