"ValueTuple <T1, T2>" exists both in "System.ValueTuple ..." and in "mscorlib ..."
In "N
I am trying to use the new Tuple features in C # 7 and run into a problem. In fact, they worked perfectly, and I'm not sure what has changed to make them break.
I am working with ASP.Net 4 , MVC 5 targeting .net framework 4.6.1
So, to use the tuples, I had to install the Nuget package 'System.ValueTuple' . Without this, the project will not compile. For some time it worked fine. Then today, when I load any page using Tuples, I get
Compiler Error Message: CS0433: The type 'ValueTuple' exists as in System.ValueTuple, Version = 4.0.2.0, Culture = neutral, PublicKeyToken = cc7b13ffcd2ddd51 and mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089 '
The project compiles fine, and if I delete System.ValueTuple , then it does not compile. But when I run it on a webpage, I get this error.
My google searches suggest that ValueTuple was added in .net 4.7 , but I do not have a link to 4.7 anywhere in my project, and I am not compiling against 4.7. My VS 2017 does not even have this option.
thanks
ASP.NET web pages are compiled at runtime, and this compilation ignores the reference assemblies that VS uses. If .NET 4.7 is available at runtime, all .NET 4.7 types, including its ValueTuple definition, will be compiled with any other definition that you might have from other DLLs.
The easiest ways to avoid this problem if you have already installed .NET 4.7, either use .NET 4.7 in your development environment or avoid compilation at runtime.
For the first, you will need to install the .NET 4.7 targeting package. This should be an option in the Visual Studio installer. When you do this, you can avoid the ValueTuple NuGet package and thereby conflict.
For the latter, you can enable precompilation when publishing your web project. When you do this, all compilation that usually occurs at runtime occurs at publication time, in a controlled manner, where the .NET 4.7 add-ons are not visible.