Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error generating fakes with ITuple

We've been using the Microsoft Fakes framework in our solution for a long time to fake System.DateTime.UtcNow during testing.

More recently, though several weeks ago, we started using C# 7 features (with VS 2017), including tuples as return values from functions. Now, I created a new branch for a release. In the new branch, generating fakes fails with multiple of the messages below

4>C:\Users\...\Source\... 2017\DEV\WebApp.UnitTests\f.cs(116674,53): error CS0234: The type or namespace name 'ITuple' does not exist in the namespace 'System.Runtime.CompilerServices' (are you missing an assembly reference?) [C:\Users\...\Source\... 2017\DEV\WebApp.UnitTests\obj\Debug\Fakes\m\f.csproj] 4>C:\Users\...\Source\... 2017\DEV\WebApp.UnitTests\f.cs(116674,13): error CS0538: 'ITuple' in explicit interface declaration is not an interface [C:\Users\...\Source\... 2017\DEV\WebApp.UnitTests\obj\Debug\Fakes\m\f.csproj]

I have tried this:

  • Add Microsoft.Net.Compilers 2.4.0 NuGet to all projects
  • Upgrade all projects to target .NET 4.7 (from 4.6.1), and remove all System.ValueTuple references (seeing as those are now built-in to .NET 4.7)

I am not sure what else to try. We didn't encounter this issue when we first started using tuples and added the System.ValueTuple NuGet package. We only noticed the issue when creating a new branch. I suppose either the building of the FakesAssemblies or the restoring of NuGet packages must have triggered something.

Since then, we also noticed it happening when we Rebuild the solution.

EDIT: I have also tried to remove all Fakes assemblies, references, and configuration and starting over. Same result.

like image 974
SvenAelterman Avatar asked Oct 26 '17 16:10

SvenAelterman


1 Answers

The solution turned out to be targeting .NET Framework 4.7.1. Per the docs (RTFM, I know...), ITuple is defined in System.Runtime.CompilerServices for the first time in that release:

https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.ituple(v=vs.110).aspx

.NET Framework

Available since 4.7.1

like image 93
SvenAelterman Avatar answered Sep 28 '22 16:09

SvenAelterman