简体   繁体   English

未定义或导入预定义类型“System.ValueTuple`2”

[英]Predefined type 'System.ValueTuple`2' is not defined or imported

I have a .NET solution file with about 20 C# projects.我有一个包含大约 20 个 C# 项目的 .NET 解决方案文件。 All of them are targeting .NET Framework 4.6.2.所有这些都针对 .NET Framework 4.6.2。 Within a couple of projects, I can easily write var t = ("hello", "world");在几个项目中,我可以轻松地编写var t = ("hello", "world"); and the compiler is happy.编译器很高兴。 But within some projects of the same solution, the compilation fails with Predefined type System.ValueTuple`2 is not defined or imported for the exact same piece of code.但是在相同解决方案的某些项目中,编译失败, Predefined type System.ValueTuple`2 is not defined or imported为完全相同的代码段Predefined type System.ValueTuple`2 is not defined or imported

I've already checked the following things:我已经检查了以下几点:

  • There is no mscorlib.dll anywhere in the solution or project directories.解决方案或项目目录中的任何位置都没有mscorlib.dll
  • bin and obj have been deleted several times. binobj已被删除多次。
  • Problem can be reproduced on a colleagues computer.问题可以在同事的计算机上重现。
  • Not a single project is using the NuGet package System.ValueTuple .没有一个项目在使用 NuGet 包System.ValueTuple
  • I did a text search across all *.csproj files for ValueTuple without any match.我对ValueTuple所有*.csproj文件进行了文本搜索,没有任何匹配。

I know that there are dozens of articles related to this error.我知道有几十篇文章与这个错误有关。 But most of them are just saying: install the NuGet package or update your .NET Framework version.但他们中的大多数只是说:安装 NuGet 包或更新您的 .NET Framework 版本。 Unfortunately, none of them seems to cover the problem I'm encountering.不幸的是,它们似乎都没有涵盖我遇到的问题。 Rather than installing or upgrading anything, I'd like to understand the behavior.我不想安装或升级任何东西,而是想了解这种行为。

I finally found the culprit: there is one project targeting .NET Standard 2.0.我终于找到了罪魁祸首:有一个针对 .NET Standard 2.0 的项目。 Every .NET Framework project referencing the .NET Standard project automatically gets a reference to System.ValueTuple.dll from the GAC (in my case, this is .NET Framework 4.7.2).每个引用 .NET Standard 项目的 .NET Framework 项目都会自动从 GAC 获取对System.ValueTuple.dll的引用(在我的例子中,这是 .NET Framework 4.7.2)。
Each project without referencing the .NET Standard project does not have the reference.没有引用 .NET Standard 项目的每个项目都没有引用。 Therefore, the snippet var t = ("hello", "world");因此,片段var t = ("hello", "world"); cannot be used.不能使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 三元运算符|| 未定义或导入预定义类型'System.ValueTuple`3' - ternary operator || Predefined type 'System.ValueTuple`3' is not defined or imported 升级到.NET 4.7后,“未定义或导入预定义类型System.ValueTuple” - “Predefined type System.ValueTuple is not defined or imported” after upgrading to .NET 4.7 Roslyn未来分支不能使用C#7特征元组 - 错误CS0518预定义类型'System.ValueTuple`2 - Roslyn future branch cannot use C# 7 feature tuples - Error CS0518 Predefined type 'System.ValueTuple`2 传递给ViewDataDictionary的模型项的类型为'System.ValueTuple`2 - The model item passed into the ViewDataDictionary is of type 'System.ValueTuple`2 .net核心System.ValueTuple - .net Core System.ValueTuple 未定义或导入预定义类型 System.Range - predefined type System.Range is not defined or imported 未定义或导入预定义类型System.Object - Predefined type System.Object is not defined or imported 未定义或导入预定义类型“System.String” - Predefined type 'System.String' is not defined or imported System.ValueTuple 4.4.0 -> 4.5.0 有什么变化? - What changed in System.ValueTuple 4.4.0 -> 4.5.0? 无法加载文件或程序集“System.ValueTuple” - Could not load file or assembly 'System.ValueTuple'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM