question

ChristianFahrenholz-2906 avatar image
0 Votes"
ChristianFahrenholz-2906 asked TianyuSun-MSFT commented

GENERATEFAKES of MS Fakes fails with CS1705 sporadically

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=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' which has a higher version than referenced assembly 'System.ValueTuple' with identity 'System.ValueTuple, Version=4.0.2.0, 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 4.0.3.0).

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

dependencies[".NETFramework,Version=v4.6.2"]["Microsoft.CodeAnalysis.Common"]

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 4.0.2.0.

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

<Reference Include="System.ValueTuple">
      <HintPath>[PathToXX]\bin\Debug\System.ValueTuple.dll</HintPath>
      <Aliases>svt</Aliases>
      <EmbedInteropTypes>False</EmbedInteropTypes>
    </Reference>


But at this path the correct version 4.0.3.0 is located. The whole source and all bin output folders do not contain a version 4.0.2.0, 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">
       <HintPath>C:\Users\myuser\.nuget\packages\system.valuetuple\4.5.0\ref\net461\System.ValueTuple.dll</HintPath>
       <EmbedInteropTypes>False</EmbedInteropTypes>
     </Reference> 

Our solution contains several net462 classic projects (Package Reference Style) and also some sdk style projects, some of our project do also reference Asp.net 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="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
  <Assembly Name="xx"/>
  <StubGeneration>
    <Clear/>
    <Add Interfaces="true"/>
    <Remove TypeName="xyz"/>
  </StubGeneration>
  <!--Shim do not make sense for interfaces-->
  <ShimGeneration>
    <Clear/>
  </ShimGeneration>
  <Compilation>
    <Property Name="PlatformTarget">x64</Property>
    <Property Name="AutoGenerateBindingRedirects">True</Property>
    <Property Name="GenerateBindingRedirectsOutputType">True</Property>
  </Compilation>
</Fakes>


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

EDIT:
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=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" and "System.ValueTuple, Version=4.0.3.0, 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=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" was chosen because it was primary and "System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" was not. [[PathToMyTestProjectFolder]\obj\Debug\Fakes\xx\f.csproj]


dotnet-csharpvs-msbuildvs-testing
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @ChristianFahrenholz-2906 ,

Welcome to Microsoft Q&A forum. I think the fake framework "wants" to use a previous version of assembly 4.0.2.0, but in your project the used version of this assembly is 4.0.3.0. Perhaps updating(haven’t tested and not sure) the Fake framework to use 4.0.3.0 or use binding redirect may work.

0 Votes 0 ·

Hi @TianyuSun-MSFT ,

thanks for your reply! How can I update the fakes framework? I mean I just do add a fakes assembly via Visual Studio Sulution Explorer context menue and VS manages the necessary alls to the fakes framework under the hood. How can I influence the version of the fakes framework used by VS? The binding redirect in the app.config, resulting from he unist test project build, is already having an entry for redirecting everything to 4.0.3.0.
Build output shows that this fakes.exe is used: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VisualStudio\v17.0\Fakes\fakes.exe"

0 Votes 0 ·
TianyuSun-MSFT avatar image TianyuSun-MSFT ChristianFahrenholz-2906 ·

Hi @ChristianFahrenholz-2906 ,

Yes, it is a little hard to directly update the fakes framework, but I thought binding redirect should work. Anyways, could you try to install this assembly(System.ValueTuple assembly version 4.0.3.0) in GAC and check if this works?

0 Votes 0 ·

0 Answers