[英]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:我已经检查了以下几点:
mscorlib.dll
anywhere in the solution or project directories.mscorlib.dll
。bin
and obj
have been deleted several times. bin
和obj
已被删除多次。System.ValueTuple
.System.ValueTuple
。*.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.