我有一个针对 .net 框架 4.52 的 MVC 5 项目,我通过 Nuget 安装了 System.ValueTuple。我在 Windows 7 上使用 Visual Studio 2017。在开发过程中,Visual Studio 不会抱怨 Tuple 返回类型,但是当我构建时出现一系列错误:
error CS1519: Invalid token '(' in class, struct, or interface member declaration
error CS1519: Invalid token ',' in class, struct, or interface member declaration
error CS1519: Invalid token ')' in class, struct, or interface member declaration
error CS1520: Method must have a return type
error CS1026: ) expected
and more..
这是破坏的方法:
public (bool, string) GetSettings()
{
if (settingsFile.IsNullOrEmpty())
throw new Exception("Settings file is null or empty!");
try
{
var definition = new { active = false, excludeList = "" };
var obj = JsonConvert.DeserializeAnonymousType(settingsFile, definition);
return (obj.active, obj.excludeList);
}
catch
{
//TODO: log exception.
return (false, string.Empty);
}
}
我不知道如何解决这个问题,只是认为它与我的框架版本不兼容。几项广泛的在线搜索对此一无所知。