C#7 ValueTuple编译错误 [英] C# 7 ValueTuple compile error

查看:84
本文介绍了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上的此处打开: https://github.com/ dotnet / roslyn / issues / 16200

Issue open on github here: https://github.com/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编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆