C#7 ValueTuple编译错误

编程入门 行业动态 更新时间:2024-10-22 12:28:49
本文介绍了C#7 ValueTuple编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用VS2017 RC,我的应用程序目标是网络框架4.6.1。

I'm using VS2017 RC and my application targets net framework 4.6.1.

我有两个引用System.ValueTuple 4.3的程序集

I have two assemblies referencing System.ValueTuple 4.3

MyProject.Services MyProject.WebApi

MyProject.Services MyProject.WebApi

在MyProject.Services中,我有一个带有此类方法的类

In MyProject.Services I have a class with a method like this

public async Task<(int fCount, int cCount, int aCount)> GetAllStatsAsync() { // Some code... return (fCount, cCount, aCount); }

在MyProject.WebApi中,我有一个使用以下方法的控制器: / p>

In MyProject.WebApi I have a controller that use this method like that:

public async Task<HttpResponseMessage> GetInfoAsync() { // Some code... var stats = await _myClass.GetAllStatsAsync(); var vm = new ViewModel { FCount = stats.fCount, CCount = stats.cCount, ACount = stats.aCount }; return Request.CreateResponse(HttpStatusCode.OK, vm); }

Intellisense可以正常工作并解构元组,但是当我编译它时会失败而没有任何错误在错误列表窗口中。 在输出窗口中,我遇到以下错误:

Intellisense is working and deconstruct the tuple but when I compile it fails without any Error in Error List window. In the output windows I have this errors:

2> MyController.cs(83,31,83,40):错误CS1061:'ValueTuple'不包含'fCount'的定义,并且找不到扩展名方法'fCount'接受类型为'ValueTuple'的第一个参数(您是否缺少using指令或程序集引用?)2> MyController.cs(84,39,84,49):错误CS1061:'ValueTuple'不包含'cCount'的定义,也没有扩展方法'cCount'接受找到类型为'ValueTuple'的第一个参数(您是否缺少使用指令或程序集引用?)2> MyController.cs(85,35,85,40):错误CS1061:'ValueTuple'不包含'aCount'的定义,并且找不到扩展方法'aCount'接受类型为'ValueTuple'的第一个参数(为您是否缺少using指令或程序集引用?)

2>MyController.cs(83,31,83,40): error CS1061: 'ValueTuple' does not contain a definition for 'fCount' and no extension method 'fCount' accepting a first argument of type 'ValueTuple' could be found (are you missing a using directive or an assembly reference?) 2>MyController.cs(84,39,84,49): error CS1061: 'ValueTuple' does not contain a definition for 'cCount' and no extension method 'cCount' accepting a first argument of type 'ValueTuple' could be found (are you missing a using directive or an assembly reference?) 2>MyController.cs(85,35,85,40): error CS1061: 'ValueTuple' does not contain a definition for 'aCount' and no extension method 'aCount' accepting a first argument of type 'ValueTuple' could be found (are you missing a using directive or an assembly reference?)

我尝试添加 D EMO 和 DEMO_EXPERIMENTAL 会建立标记,但仍然失败。

I tried adding the DEMO and DEMO_EXPERIMENTAL build flags but still fails.

有什么问题的想法吗?

编辑1:

此代码有效,并且统计数据的结构也很好。

This code works and stats is well deconstructed. I'm probably hitting a bug.

public async Task<HttpResponseMessage> GetInfoAsync() { // Some code... var stats = await _myClass.GetAllStatsAsync(); var tu = stats.ToTuple(); var vm = new ViewModel { FCount = tu.Item1, CCount = tu.Item2, ACount = tu.Item3 }; return Request.CreateResponse(HttpStatusCode.OK, vm); }

编辑2:

问题在github上的此处打开: github/ dotnet / roslyn / issues / 16200

Issue open on github here: github/dotnet/roslyn/issues/16200

推荐答案

如果有人陷入同一陷阱,则需要解决此问题更新此软件包: Microsoft.Net.Compilers到2.0(您需要显示预发布版本)

If anyone falls in the same trap, to fix this you need to update this package: Microsoft.Net.Compilers to 2.0 (you need to show pre-release)

更多推荐

C#7 ValueTuple编译错误

本文发布于:2023-11-03 15:41:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555474.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   ValueTuple

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!