GENERATEFAKES of MS Fakes fails with CS1705 sporadically - c#

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]
3> 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]

As stated in my comment above, I have found a workround for our situation:
Within the project that should be faked we have introduced last week a c# tuple in an interface method signature. I have changed the tuple to a class so now the interface does not need the c# tuple anymore. The build succeeds but the three warnings I mentioned in the OP at the end of the post are still there.

Related

MSBuild.exe gives errors about Nuget package conflicts, what does it mean?

Working in VS2017 I have a C# project .Net 4.6 using several Nuget packages. On my dev machine from within VS it builds just fine, I've tested it will restore Nuget packages from completely clean and build correctly.
On our build machine it is build using MSBuild.exe and now everything is going wrong.
Build>"C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" ".sln"
/p:Configuration="Release" /p:Platform="Any CPU" /p:version=4.2.0.3230
/m " Microsoft (R) Build Engine version 15.7.179.6572 for .NET
Framework Copyright (C) Microsoft Corporation. All rights reserved.
I can see the /packages sub-dir is getting populated as expected with packages but then I get errors like:
Encountered conflict between 'Reference:System.Numerics.Vectors,
Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,
processorArchitecture=MSIL' and
'Platform:System.Numerics.Vectors.dll'. Could not determine winner
because 'Reference:System.Numerics.Vectors, Version=4.1.4.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,
processorArchitecture=MSIL' does not exist.
Encountered conflict between 'Platform:System.Numerics.Vectors.dll' and
'Reference:System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL'. Could
not determine winner because 'Reference:System.Numerics.Vectors,
Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,
processorArchitecture=MSIL' does not exist.
My project file looks like:
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2106,5):
warning MSB3245: Could not resolve this reference. Could not locate
the assembly "log4net, Version=2.0.8.0, Culture=neutral,
PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL". Check to
make sure the assembly exists on disk. If this reference is required
by your code, you may get compilation errors.
[]
For SearchPath "{HintPathFromItem}".
Considered "packages\log4net.2.0.8\lib\net45-full\log4net.dll", but it didn't
exist.
I mean, here it is:
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
</Reference>
Every build is a completely clean build (it's wiped between) so I can clearly see Nuget has downloaded log4net.dll
I am getting loads of these and I cannot see any explanation why, or where to start looking for a solution. Everything looks to be where it should be
You can try changing a binding redirect in your config file to 2.8.0 of log4net
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.8.0" newVersion="2.0.8.0" />

Visual Studio Android solution stops building upon hitting C# version conflict when using MSBuild

The solution builds fine in Visual Studio 2017.
MSBuild will produce the following warning:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets (2106, 5): warning MSB3277: Found conflicts between different versions of "Microsoft.CSharp" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
A couple line will show up after the warning, but from there it halts and doesn't progress at all.
The actual reference conflict is here:
There was a conflict between "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". (TaskId:123)
4> "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not. (TaskId:123)
4> References which depend on "Microsoft.CSharp, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll]. (TaskId:123)
4> C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll (TaskId:123)
4> Project file item includes which caused reference "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Microsoft.CSharp.dll". (TaskId:123)
4> Microsoft.CSharp (TaskId:123)
4> References which depend on "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" []. (TaskId:123)
4> C:\Users\laniganr.nuget\packages\newtonsoft.json\10.0.3\lib\netstandard1.3\Newtonsoft.Json.dll (TaskId:123)
A couple other lines will show up right after the error, but never progresses past this point.
Said lines:
_XamarinAndroidBuildAarRestore:
Reference has already had resources merged, skipping due to: obj\ReleaseNuget\XbdMerge\Xamarin.GooglePlayServices.Bas
ement.dll.stamp
Reference has already had resources merged, skipping due to: obj\ReleaseNuget\XbdMerge\Xamarin.GooglePlayServices.Tas
ks.dll.stamp
Reference has already had resources merged, skipping due to: obj\ReleaseNuget\XbdMerge\Xamarin.Firebase.Common.dll.st
amp
Reference has already had resources merged, skipping due to: obj\ReleaseNuget\XbdMerge\Xamarin.Firebase.Iid.dll.stamp
Reference has already had resources merged, skipping due to: obj\ReleaseNuget\XbdMerge\Xamarin.Firebase.Messaging.dll
.stamp
_ResolveLibraryProjectImports:
Skipping target "_ResolveLibraryProjectImports" because all output files are up-to-date with respect to the input files
.
_BuildLibraryImportsCache:
Skipping target "_BuildLibraryImportsCache" because all output files are up-to-date with respect to the input files.
Visual Studio Android solution stops building upon hitting C# version conflict when using MSBuild
That because there is an explicit reference to Microsoft.CSharp 2.0.5.0 in the Xamarin.Android project when there is a reference to Microsoft.CSharp 4.3.0.0 in the netstandard library project from a library newtonsoft.json 10.0.3.
In the build log, you can find your project referencing the package newtonsoft.json in following message:
C:\Users\xxxxx\packages\newtonsoft.json\10.0.3\lib\netstandard1.3\Newtonsoft.Json.dll
(TaskId:123)
Then check the dependence of the package newtonsoft.json\10.0.3\lib\netstandard1.3:
To resolve this issue, you can try to update Newtonsoft.Json to the version 11.0.1 and above. This is because this version of Newtonsoft.Json package for netstandard 2.0 has no dependency to Microsoft.CSharp.
Alternatively, you can remove the Microsoft.CSharp 2.0.5 and allow the one from Nuget to be used.
You can refer to the similar thread here and here for some more details.
Hope this helps.

System.Net.Http version not lining up in the references list

We have a project on .Net 4.6.1 that we've added IdentityServer packages to.
One error we're getting is apparently solved by updating the System.Net.Http.dll to version 4.3.3 (https://github.com/aspnet/Security/issues/1116)
Problem seems to be that VS 2017 (15.7.3) only references C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.Net.Http.dll and not packages\System.Net.Http.4.3.3\lib\net46\System.Net.Http.dll even if I manually add it. At least that's the path shown in the reference details window and the version that ends up in the bin folder.
Looking in the .csproj it shows
<Reference Include="System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\System.Net.Http.4.3.3\lib\net46\System.Net.Http.dll</HintPath>
</Reference>
One other things that complicates this is that there's no matrix between NuGet versions, file versions, and assembly versions that I could find to help me figure this out.
I'm checking multiple environments but I can only get the file version and there's nothing to cross check that against.
NuGet Package 4.3.3 = File Version: 4.6.25705.1
The version in the framework dir = 4.6.26011.1
Some version in one of our envs that doesn't work = 4.6.25514.4

Why isn't .NET looking in my output path for any binaries?

I've inherited a Visual Studio web project and the Output Path is specified as objd\amd64\. When I build, all the files (both compiled project files along with packages, such as MVC) show up there. However, when I hit F5 to run the app, I get the following exception:
Could not load file or assembly 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
The exception goes on to list places where the system is looking for that (and other) files. The first place it looks is bin, which is the normal output folder. Why isn't .NET looking in the specified output folder, and how can I make it look there?
CLARIFICATION: Just to be clear, this exception is not unique to MVC. If I manually create the bin folder and copy the MVC DLL there, then I get past this exception, but get another one for the next file it looks for. If I copy all the files to bin, then the app runs fine. The runtime just isn't looking in the specified output folder for the files.
UPDATE: If I change the Output Path to bin, NO files are output there. There is no post-build event defined that I can see.
UPDATE: Here are my build settings. The bin folder isn't even being created when I build the project (I'm trying to use bin for test purposes), let alone getting files copied into it. Debug is definitely the selected build type when I hit F5.
UPDATE: Here are the Solution config settings:
Could not load file or assembly 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
The error is a compile error. This means the build is crashing before the MVC runtime is launched.
This is easy to prove. Delete the bin folder and try to compile again. If it is not re-created and/or there are a lot of files missing, it means the build is not making it all the way through.
Some things that could be causing this are:
Mismatching MVC (and/or MVC dependency) version numbers between 2 different .csproj files in your solution.
Mismatching MVC (and/or MVC dependency) version numbers between your .csproj file and web.config and/or /Views/web.config.
One or more .csproj files has an invalid <HintPath> for an MVC (and/or MVC dependency) DLL reference location.
NuGet package restore is not set up at all or is not set up properly. The easy way to check this is to look in your packages/ folder to see if the reference in the error message exists on disk.
The best (safest) way to solve this is to go through these files manually. Visual Studio doesn't always make the right decisions when upgrading dependency versions or changing file locations.
Typical MVC 5 references and versions should look like this in the .csproj file (you may need to adjust the version numbers and net45x version in the <HintPath> accordingly):
<Reference Include="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.0.0\lib\net45\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.Razor.3.0.0\lib\net45\System.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.0.0\lib\net45\System.Web.WebPages.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.0.0\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
Update
I see you have posted Visual Studio's project properties. The configuration is highly customized and I don't recommend you use Visual Studio's project property designer to edit it, because it could cause the configuration to become corrupted.
My suggestion is to use the following procedure to review your .csproj file references. This is much safer than deleting references and re-adding them, since Visual Studio doesn't support a way to edit everything in the .csproj file that could be there.
Right-click on your project node in Solution Explorer and click Unload Project.
Right-click the project node again and click Edit .csproj.
Search the file for references to each of the above assemblies and update the version and the HintPath accordingly. Make sure the HintPath you use actually points to an existing file on disk.
Repeat these steps for all dependent projects in the solution (and any that are in DLLs that are not part of the solution).
You should also review the assembly versions (especially those of MVC) in your web.config and Views/web.config and update them, if necessary. See the link for more detailed information.
Update the Application web.config File
Be sure to make these changes in the app web.config file, not the web.config file in the Views folder.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

CS0246: The type or namespace name 'CrystalDecisions' could not be found

I trying open already created ASP.NET project in another PC locally via IIS manager. But I'm getting this error:
CS0246: The type or namespace name 'CrystalDecisions' could not be found (are you missing a using directive or an assembly reference?)
I've tried the following to resolve this:
Added Namespaces :
CrystalDecisions.CrystalReports.Engine;
CrystalDecisions.Shared;
CrystalDecisions.ReportSource;
Target Framework set to .Net Framework 4.
Installed CrystalDecisions.CrystalReports.Engine via NuGet Package manager.
Try this:
Locate your C# project file ( YourProjectName.csproj ).
Open it using Notepad++ or any other text editor.
Press Ctrl + F and find for <Reference Include=
There should be a CrystalDecisions.CrystalReports.Engine
If it isn't add this, use the correct version:
<Reference Include="CrystalDecisions.CrystalReports.Engine, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL" />
<Reference Include="CrystalDecisions.ReportSource, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL" />
<Reference Include="CrystalDecisions.Shared, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL" />
<Reference Include="CrystalDecisions.Windows.Forms, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL" />
<Reference Include="FlashControlV71, Version=1.0.3187.32366, Culture=neutral, PublicKeyToken=692fbea5521e1304" />
I just faced this error while running a windows forms application in VS 2019 and below were the steps I took to resolve it:
I checked the references node (In project explorer) and all the 4 CrystalDecision packages were there but with a yellow warning icon to all of them so I deleted them all.
Then I opened the Nuget package manager to search for each of the packages starting from CrystalDecisions.CrystalReports.Engine. They were all marked as "installed" so I uninstalled and reinstalled them one after the other. And then I built the project successfully.
This process removed the packages from the Packages.config file and added them back after installation.
What I noticed was just that the .Net framework version for the packages in the packages.config file was changed from net45 to net40.
So apparently, I have been referencing the wrong .Net version but I wouldn't have realized because the project was building fine before I switched to VS2019.
I reopen the project folder by File>Open>Web Site... and save anoter solution, and the error missing.

Categories