Error de compilación de C# 7 ValueTuple
Estoy usando VS2017 RC y mi aplicación se dirige a net framework 4.6.1.
Tengo dos asambleas Sistema de referencia.Valor 4.3
Mi proyecto.Servicio Mi proyecto.WebAPI
En mi proyecto.Servicios tengo una clase con un método como este
public async Task<(int fCount, int cCount, int aCount)> GetAllStatsAsync()
{
// Some code...
return (fCount, cCount, aCount);
}
En mi proyecto.WebAPI Tengo un controlador que usa este método así:
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 está trabajando y deconstruye la tupla, pero cuando compilo falla sin ningún Error en la ventana de la Lista de Errores. En el ventanas de salida Tengo este error:
2>MyController.cs (83,31,83,40): error CS1061: 'ValueTuple' no contiene una definición para 'fCount' y no tiene extensión método 'fCount' aceptar un primer argumento de tipo 'ValueTuple' se podría encontrar (¿le falta una directiva de uso o un referencia de ensamblado?) 2 > MyController.cs (84,39,84,49): error CS1061: 'ValueTuple' no contiene una definición para 'uenta' y ningún método de extensión 'uenta' aceptar un primer argumento de tipo 'ValueTuple' podría ser encontrado (¿te falta un uso directiva o una referencia de montaje?) 2 > MyController.cs (85,35,85,40): error CS1061: 'ValueTuple' no contiene un definición para 'aCount' y ningún método de extensión' aCount ' que acepte un el primer argumento de tipo 'ValueTuple' podría ser encontrado (son falta una directiva using o una referencia de ensamblado?)
Intenté agregar las banderas de compilación DEMO y DEMO_EXPERIMENTAL pero aún falla.
Cualquier idea ¿en qué está mal?
EDITAR 1:
Este código funciona y las estadísticas están bien deconstruidas. Probablemente estoy golpeando un micrófono.
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);
}
EDITAR 2:
Edición abierta en github aquí: https://github.com/dotnet/roslyn/issues/16200
2 answers
Si alguien cae en la misma trampa, para arreglar esto necesita actualizar este paquete: Microsoft.Net.Compilers a 2.0 (necesita mostrar pre-release)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-10 09:37:32
Creo que es porque no has definido fCount, cCount y aCount. Prueba esto
public async Task<(int fCount, int cCount, int aCount)> GetAllStatsAsync()
{
// Some code...
//fCount, cCount, aCount are not defined here, so you should define them
var fCount = 0;
var cCount= 0;
var aCount = 0;
return (fCount , cCount, aCount );
//Other ways:
//return (fCount : 0, cCount: 0, aCount : 0);
//return new (int fCount , int cCount, int aCount ) { fCount = 0, cCount = 0, aCount = 0 };
}
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);
}
Editado con la sugerencia @ Swell
Echa un vistazo a este post
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-03 15:17:28