GENERATEFAKES of MS Fakes fails with CS1705 sporadically

Christian Fahrenholz 1 Reputation point

I posted this already on Stackoverflow, I am not sure if you guys will notice it there so I post it also here.

On my machine the unit test project build fails since a few days but not every time. On the machine of my colleague it fails also sometimes but most of the time he just needs to rebuild and build succeeds.

Assembly 'xx' with identity '...' uses 'System.ValueTuple, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' which has a higher version than referenced assembly 'System.ValueTuple' with identity 'System.ValueTuple, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' [PathToTestDir\obj\Debug\Fakes\xx\f.csproj]
GENERATEFAKES : error : project compilation failed with exit code 1

I have checked all nuget references in our solution of all projects (also in project.assests.json and packages.lock.json) and all of them are referencing System.ValueTuple package Version 4.5.0 (assembly version

In packages.lock.json I see the following dependency at this json path:


which is this one:

"Microsoft.CodeAnalysis.Common": {"type": "Transitive", "resolved": "2.8.0",...

and this contains a dependency to:

"System.ValueTuple": "4.3.0"

which has assembly version

What I also see in the generated f.csproj file is this hintpath:

   <Reference Include="System.ValueTuple">  

But at this path the correct version is located. The whole source and all bin output folders do not contain a version, except in the obj folder for those fakes generated assemblies.

For all other projects that we reference as fakes the MS Fakes tool is generating this hint path:

<Reference Include="System.ValueTuple">  

Our solution contains several net462 classic projects (Package Reference Style) and also some sdk style projects, some of our project do also reference core 2.1. Our unit test project is using Microsoft Fakes and MS-Test since years. We are using VS 2022 (17.1.6).

What I have tried so far:
* Closing VS, deleting all bin and obj folders, deleting nuget cache, restarting VS, rebuilding (it worked one time for me so far, but now I am stuck again for days now)
* Setting AutoGenerateBindingRedirects and GenerateBindingRedirectsOutputTypeto in the unit test project to True
* Also in the .fakes file I tried to set these two properties (even when GenerateBindingRedirectsOutputType makes not much sense for fakes assembly).
* Tried out this SO answer

so my fakes file looks like this after these unsuccessful attempts:

   <Fakes xmlns="" Diagnostic="true">  
     <Assembly Name="xx"/>  
       <Add Interfaces="true"/>  
       <Remove TypeName="xyz"/>  
     <!--Shim do not make sense for interfaces-->  
       <Property Name="PlatformTarget">x64</Property>  
       <Property Name="AutoGenerateBindingRedirects">True</Property>  
       <Property Name="GenerateBindingRedirectsOutputType">True</Property>  

I would appreciate any help or hint so much, thanks!

I also see these warnings in the output window:

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3277: Found conflicts between different versions of "System.ValueTuple" that could not be resolved. [[PathToMyTestProjectFolder]\obj\Debug\Fakes\xx\f.csproj]

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3277: There was a conflict between "System.ValueTuple, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" and "System.ValueTuple, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51". [[PathToMyTestProjectFolder]\obj\Debug\Fakes\xx\f.csproj]

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5): warning MSB3277: "System.ValueTuple, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" was chosen because it was primary and "System.ValueTuple, Version=, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" was not. [[PathToMyTestProjectFolder]\obj\Debug\Fakes\xx\f.csproj]

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,228 questions
Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
327 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,936 questions
{count} votes