I'm using VS2017 RC 15.0.26014 and my application targets net framework 4.6.1.
I have two assemblies referencing System.ValueTuple 4.3
MyProject.Services
MyProject.WebApi
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);
}
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 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): error CS1061: 'ValueTuple
int>' does not contain a definition for 'fCount' and no extension
method 'fCount' accepting a first argument of type 'ValueTupleint, int>' 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?)
I tried adding the __DEMO__ and __DEMO_EXPERIMENTAL__ build flags but still fails.
Any idea on what's wrong?
EDIT 1:
This code works and stats is well deconstructed, I can see the values when debugging. 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);
}
@swellfr Thanks for reporting this.
So far I'm having trouble to reproduce this issue. If your project is smaller enough (and is not sensitive) would you mind sharing the code?
I believe the error you copied contains an important clue, but I can't quite make sense of it yet. The clue is that it complains about ValueTuple<int, int, int> rather than (int, int, int). That tells me the consuming project doesn't recognize the ValueTuple from the library as a proper tuple type. I'll need to investigate more.
For my own reference, below is the basic test I used. I ran a few variations but didn't hit this issue so far.
@VSadov Do you have any inspiration on this puzzle?
```C#
[Fact]
[WorkItem(16200, "https://github.com/dotnet/roslyn/issues/16200")]
public void Issue16200()
{
var libSource = @"
public class C
{
public static async System.Threading.Tasks.Task<(int a, int b)> M()
{
await System.Threading.Tasks.Task.Run(() => { });
return (1, 2);
}
}";
var libComp = CreateCompilationWithMscorlib46(libSource, references: s_valueTupleRefs, options: TestOptions.DebugDll);
libComp.VerifyDiagnostics();
var source = @"
public class D
{
async void M2()
{
var x = await C.M();
System.Console.Write(x.a);
}
}";
var comp = CreateCompilationWithMscorlib46(source, references: new[] { libComp.EmitToImageReference(), ValueTupleRef, SystemRuntimeFacadeRef }, options: TestOptions.DebugDll);
comp.VerifyDiagnostics(); // no error on x.a
}
```
@jcouv I tried a small sample but it was working.
I'm going to remove everything from the project in order to give you a minimal sample.
@jcouv I removed 99% of the project, but just in case I missed something is there a way to send you the project to a private place?
@swellfr Thanks!
My email is [email protected] referencing GitHub issue 16200. If the project is too big to send by email, then you can email me a dropbox, OneDrive or Google Drive link.
Also, if possible, could I ask to more things from you:
csc.exe? Its location should be listed in the Output window when you build the solution. On my machine it is in C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin. Then right-click, select Properties, then Details tab. My product version looks like "2.0.0-rc2-61213-05. Commit Hash: 3b369f41d4...". I'm interested in the commit hash (the first 8 characters should be enough).@swellfr Thanks for the repro project.
The problem is in your build definition. The client project is building using it's own version of csc.
The way this is visible is that you cannot use tuple syntax in the client. It gives you parsing errors, which indicates that the compiler does not recognize C#7.0 syntax.
Based on this, I will close the issue as by design.
```C#
public Task
{
var t2 = (1, 2);
throw null;
}
2>C:UsersjcouvDesktopNewDealsrcNewDealAPIControllersAgreementFactoriesController.cs(24,24,24,25): error CS1026: ) expected
2>C:UsersjcouvDesktopNewDealsrcNewDealAPIControllersAgreementFactoriesController.cs(24,26,24,27): error CS1001: Identifier expected
2>C:UsersjcouvDesktopNewDealsrcNewDealAPIControllersAgreementFactoriesController.cs(24,26,24,27): error CS1002: ; expected
2>C:UsersjcouvDesktopNewDealsrcNewDealAPIControllersAgreementFactoriesController.cs(24,27,24,28): error CS1002: ; expected
2>C:UsersjcouvDesktopNewDealsrcNewDealAPIControllersAgreementFactoriesController.cs(24,27,24,28): error CS1513: } expected
Here's the `csc` that runs on my box for the client project.
```C#
2>CscToolExe = csc.exe
2>CscToolPath = C:\Users\jcouv\Desktop\NewDeal\packages\Microsoft.Net.Compilers.1.3.2\build\..\tools
2>CSharpCoreTargetsPath = C:\Users\jcouv\Desktop\NewDeal\packages\Microsoft.Net.Compilers.1.3.2\build\..\tools\Microsoft.CSharp.Core.targets
@swellfr One more thing to add: you can either modify your project targets so that the client is also compiled with C#7.0, or you can use C#6 syntax (as you did in EDIT 1 in the original issue description).
Got it working, showing the pre-release of Microsoft.Net.Compilers did it!
Thanks
Just installed 2017. I didn't realize for a while I had to install a pre-release update to Microsoft.Net.Compilers, but that fixed my errors. I also had to change web.config manually to "/langversion:7" (was 6).
Most helpful comment
Got it working, showing the pre-release of Microsoft.Net.Compilers did it!
Thanks