System references in bamboo - c#

I have installed one nuget package in my project which has dependency on some of the system dlls like system.IO/system.Reflection etc. So when I install that nuget package everything works fine in my local. However, when I push my code to bamboo (build server) I start getting multiple assemblies error:
26-Mar-2019 05:30:23 CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'E:\agt01\ENS-EB577-BEQI\Bin\Packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll' and 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\Facades\System.Xml.ReaderWriter.dll'. Remove one of the duplicate references. [E:\agt01\ENS-EB577-BEQI\myProject\myProject.csproj]
26-Mar-2019 05:30:23 CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'E:\agt01\ENS-EB577-BEQI\Bin\Packages\System.Runtime.InteropServices.4.3.0\lib\net462\System.Runtime.InteropServices.dll' and 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\Facades\System.Runtime.InteropServices.dll'. Remove one of the duplicate references. [E:\agt01\ENS-EB577-BEQI\myProject\myProject.csproj]
26-Mar-2019 05:30:23 CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'E:\agt01\ENS-EB577-BEQI\Bin\Packages\System.Reflection.4.3.0\lib\net462\System.Reflection.dll' and 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\Facades\System.Reflection.dll'. Remove one of the duplicate references. [E:\agt01\ENS-EB577-BEQI\myProject\myProject.csproj]
26-Mar-2019 05:30:23 CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'E:\agt01\ENS-EB577-BEQI\Bin\Packages\System.IO.4.3.0\lib\net462\System.IO.dll' and 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\Facades\System.IO.dll'. Remove one of the duplicate references. [E:\agt01\myProject-EB577-BEQI\myProject\myProject.csproj]
26-Mar-2019 05:30:23
26-Mar-2019 05:30:23 617 Warning(s)
26-Mar-2019 05:30:23 4 Error(s)
So basically bamboo is trying to pick those system dlls from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\Facades\
So to work that around, I have to make sure I remove these references from my csproj as nuget packages and push to bamboo in order to get a successful build but when testing in my local I have to add them as nuget packages to get things to work.
Has any one faced such issue before?

For the specific errors you included, it looks as though you have duplicate imports of the assemblies within your .csproj file. I would open up the myProject.csproj and pick either the ones in Bin\Packages or the System ones installed as part of the .Net Framework install.
I personally would go with the System installed ones that were put there as part of the framework install. If you are having issues finding those on the Bamboo agent, make sure that .NET Framework 4.6.2 is installed on the build agent in the specified location (C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2)

Related

Could not load file or assembly 'System.Collections.Immutable' but i don't have any references to it

I'm on V16.4.1 and the project is targeting .NET Framework 4.7.1
I have a solution with multiple projects which all run fine except one which gives the above error. I searched the project and can't find any using references to it and just in case, I added the dll to my references. I searched the entire solution in case I was referencing it through another project but there is no reference to it anywhere
I tried deleting bin & obj folders. Cleaned and rebuilt the project but I get the same error every time.
Edit: The project can build, this only happens when I try to debug it
bin\roslyn\csc.exe is throwing the exception
Could not load file or assembly 'System.Collections.Immutable,
Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The system cannot find the file specified.
I use
Visual Studio Professional 2019 ver 16.7.6 / Preview: 16.8.0 Preview 4
and I found the same problem with many 'old' project using .net framework when I compile them from scratch (i.e. deleting bin/obj directories).
The compiler does not recognize that the runtime needs this package, and the solution is to copy in the bin directory the requested version (1.2.3.0 in this case) of DLL System.Collections.Immutable.dll
You can download it adding this line to packages.config file:
<package id="System.Collections.Immutable" version="1.2.3.0" targetFramework="net471" />
but still need to manually copy the .dll in bin directory.
Or add the package with Nuget.
Stefano's answer worked for me
this file is a dependency from my firebase dll, tough i didn't need to modify packages.config because the file exists in my bin folder
I just included System.Collections.Immutable.dll file in in VS project
then changed in file properties > advanced > copy output > copy always
thanks!

VS2017 Not Loading Same DLL for Projects in Same Solution

I have two projects under the same solution that both rely on `System.Net.Http' as a dependency. The strange thing is that both projects use different physical dll files, which is causing a runtime MissingMethodException error when trying to run unit tests.
library project uses:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Net.Http.dll
test project uses:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.Net.Http.dll
Why are there two instances of the assembly and how can I force VS to use a specific instance? The csproj files do not specify a specific file path:
<Reference Include="System.Net.Http" />
The only thing I can think of is I used the built in "Create Unit Tests" option when right-clicking the method in the library project. I'm guessing this loads a default set of references which does not match when you create a new project.

'Multiple assemblies with equivalent identity have been imported' - Azure Deployment [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm getting a 'Multiple assemblies with equivalent identity have been imported' error when deploying to Azure.
Here's the deployment log
Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling .NET Web Application deployment.
MSBuild auto-detection: using msbuild version '14.0' from 'D:\Program Files (x86)\MSBuild\14.0\bin'.
All packages listed in packages.config are already installed.
Filanthropy.Model -> D:\home\site\repository\Filanthropy.Model\bin\Release\Filanthropy.Model.dll
CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'D:\home\site\repository\packages\System.Runtime.InteropServices.4.1.0\lib\net462\System.Runtime.InteropServices.dll' and 'D:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\Facades\System.Runtime.InteropServices.dll'. Remove one of the duplicate references. [D:\home\site\repository\Filanthropy.Core\Filanthropy.Core.csproj]
CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'D:\home\site\repository\packages\System.Runtime.Extensions.4.1.0\lib\net462\System.Runtime.Extensions.dll' and 'D:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\Facades\System.Runtime.Extensions.dll'. Remove one of the duplicate references. [D:\home\site\repository\Filanthropy.Core\Filanthropy.Core.csproj]
CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'D:\home\site\repository\packages\System.Runtime.4.1.0\lib\net462\System.Runtime.dll' and 'D:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\Facades\System.Runtime.dll'. Remove one of the duplicate references. [D:\home\site\repository\Filanthropy.Core\Filanthropy.Core.csproj]
CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'D:\home\site\repository\packages\System.Reflection.4.1.0\lib\net462\System.Reflection.dll' and 'D:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\Facades\System.Reflection.dll'. Remove one of the duplicate references. [D:\home\site\repository\Filanthropy.Core\Filanthropy.Core.csproj]
CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'D:\home\site\repository\packages\System.IO.4.1.0\lib\net462\System.IO.dll' and 'D:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\Facades\System.IO.dll'. Remove one of the duplicate references. [D:\home\site\repository\Filanthropy.Core\Filanthropy.Core.csproj]
CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'D:\home\site\repository\packages\System.Diagnostics.Tracing.4.3.0-preview1-24530-04\lib\net462\System.Diagnostics.Tracing.dll' and 'D:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\Facades\System.Diagnostics.Tracing.dll'. Remove one of the duplicate references. [D:\home\site\repository\Filanthropy.Core\Filanthropy.Core.csproj]
Failed exitCode=1, command="D:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "D:\home\site\repository\Filanthropy.Web\Filanthropy.Web.csproj" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="D:\local\Temp\8d3fe5a038ffaf0";AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false /p:SolutionDir="D:\home\site\repository\.\\"
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\58.51019.2480\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
i've been through the relevant csproj file, and can confirm that there are no duplicates in it. This doesm't happen on my local machine, only when deploying to azure.

System.Collections.Immutable reference to System.Runtime and FxCop/metrics

On Windows 7 with .NET 4.5.2 installed, I create a new ClassLibrary project targetting .NET 4.5.2.
I want to calculate the code metrics for that assembly by launching the metrics.exe that is shipped with FxCop with Visual Studio 2013 located in c:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop\.
Everything works fine.
I then nuget System.Collections.Immutable v1.1.37.
I can see in the references that only System.Collections.Immutable is referenced since the other dependencies (System.Runtime, System.Collections, System.Diagnotics.Debug etc.) are found (I suppose in c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\Facades\)
I create a dummy method that creates a dummy ImmutableArray var foo = new List<int>().ToImmutableArray();
Everything compiles and works just fine.
I relaunch the metrics computation.
I have the following error:
metrics.exe /f:c:\dev\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll /o:toto.xml
error : CA0055 : Could not load file:
'c:\dev\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll'.
If I perform the same command on the System.Immutable.Collections assembly, I have the following error:
Calculating metrics for file 'c:\dev\ClassLibrary1\ClassLibrary1\bin\Debug\System.Collections.Immutable.dll'.
Could not locate the framework assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Now, if I copy the System.Runtime file located in c:\Windows\Microsoft.NET\Framework\v4.0.30319\ in the output directory, calculating the code metrics on ClassLibrary1.dll works fine. But if I copy the version that is in c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\Facades\, if fails again.
When debugging another library using Immutable in a web application, I can see the following in the "Loaded modules":
System.Runtime.dll C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.dll Yes No Skipped loading symbols. 544 4.06.1055.0 06/11/2015 03:49 000007FED10D0000-000007FED10D9000 [15760] w3wp.exe [4] /LM/W3SVC/2/ROOT/WebSite-2-131026947404276669
All of this makes me think that System.Collections.Immutable uses the version of System.Runtime that is in c:\Windows\Microsoft.NET\Framework\v4.0.30319\
So I thought, "let's add an explicit reference to that assembly." If I do, I got the following compilation error:
error CS1703: Multiple assemblies with equivalent identity have been imported: 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.dll' and 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.2\Facades\System.Runtime.dll'. Remove one of the duplicate references.
There something somewhere that is wrong and I can't pinpoint it.
I worked around the error by using the /ignoreinvalidtargets for metrics.exe.
Does anyone have a club about the real error?
(I also tried targetting .NET Framework 4 and adding references to all the dependant assemblies from c:\Windows\Microsoft.NET\Framework\v4.0.30319\ with CopyLocal = true. It works, despite the following warning:
Some NuGet packages were installed using a target framework different from the current target framework and may need to be reinstalled. Visit http://docs.nuget.org/docs/workflows/reinstalling-packages for more information. Packages affected: System.Collections, System.Collections.Immutable, System.Diagnostics.Debug, System.Globalization, System.Linq, System.Resources.ResourceManager, System.Runtime, System.Runtime.Extensions, System.Threading
)
Thanks.

MSBuild can no longer find dependencies after upgrading from 4.0 to 4.5?

We have a .Net 3.5 application that is built using some scripts that call msbuild.exe
Recently all our machines started automatically updating from .Net 4.0 to .Net 4.5 as part of a company-wide policty, and our build scripts started failing.
The errors given is that they cannot find a referenced assembly, like this :
error CS0012: The type 'System.Drawing.Image' is defined in an assembly that is not referenced.
You must add a reference to assembly 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
It looks like in every case, we try to build project A that has a reference to project B, and project B has a reference to library X, and get an error that project A needs a reference to library X.
A temporary workaround is to uninstall 4.5, uninstall 4.0, then re-install 4.0, however this is time consuming and not practical in an environment where updates are often silent and automatic.
I've tried using the following msbuild switches already, with no luck
/toolsversion:3.5 - Exception about Func being undefined
/toolsversion:4.0 - Does not work because 4.5 replaced 4.0 tools
/p:TargetFrameworkVersion="v3.5" - Same error
/p:VisualStudioVersion=11.0 - Same error
*` in the csproj file - Already exists, and same error
The .csproj files already has <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> specified in every single csproj file in my solution, and ToolsVersion="4.0".
I have also tried changing the TargetFrameworkVersion to 4.0, and that does not work either.
I found some notes online about Microsoft changing the flag OnlyReferenceAndBuildProjectsEnabledInSolutionConfiguration from false to true during the 4.0 to 4.5 update, however manually setting that flag in the csproj files also does not fix the issue.
<OnlyReferenceAndBuildProjectsEnabledInSolutionConfiguration>
false
</OnlyReferenceAndBuildProjectsEnabledInSolutionConfiguration>
Why is msbuild failing to find these child assemblies after upgrading from 4.0 to 4.5, and how can I fix it?
Update
I've finally figured out the source of the problem, but I have no idea how this could be happening.
ProjectA has a class which inherits from an abstract class in ProjectB, and one of the properties of ProejctB.BaseClass is of type System.Drawing.Image.
namespace ProjectA
{
public class SomeClass : BaseClass { }
}
namespace ProjectB
{
public abstract class BaseClass
{
public System.Drawing.Image GetImage() { };
}
}
From everything I've read online, and from creating a test project of my own, this means that ProjectA needs a reference to System.Drawing.Image in order to build.
But for whatever reason, this restriction does not seem to matter for our project when buliding with msbuild 4.0 or in VS 2010. It's perfectly happy to build ProjectA without a reference to System.Drawing.Image.
Even after updating to .Net 4.5, I can still build ProjectA successfully from Visual Studio 2010 without adding a reference to System.Drawing.Image, however building using msbuild now (correctly?) fails. I also get the reference errors when building in VS 2012 Express, so whatever is allowing this to occur has apparently been fixed in newer versions of VS.
For now, I have gone through all 148 projects in our solution and fixed all the references, however I want to leave this question open to try and get an answer on why I am able to build ProjectA using msbuild 4.0 or Visual Studio 2010 without a reference to System.Drawing.Image.
I have already determined that I can't easily reproduce the behavior in a test project, so my best guess is its either some configuration, some part of the build scripts, or it's a bug that existed back when the .sln or .csproj files got created and no longer exists with newly created projects.
Based on Hans' comment, it sounds like something changed in the internal C# compiler between version 4 and version 5 to fix the bug that was allowing us to build ProjectA without proper references.
This doesn't have anything to do with MSBuild, what changed is that you are using a different C# compiler. Version 5 instead 4. I've seen cursory evidence in other questions that is is more aggressive about wanting to resolve indirect type references. Nothing to nail to the wall, everybody just fixes this with the obvious solution.
When viewing the msbuild.exe log, I can see it comes down to a call to csc.exe, which contains the exact same /reference list, however fails with 4.5.
Building ProjectA with 4.0
Task "Csc"
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE /reference:C:\Path\bin\Release\ProjectB.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.Services.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug:pdbonly /filealign:512 /keyfile:ProjectA.snk /optimize+ /out:obj\Release\ProjectA.dll /target:library Properties\AssemblyInfo.cs SomeFile.cs Properties\VersionInfo.cs
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.
Done executing task "Csc".
Building ProjectA with 4.5
Task "Csc" (TaskId:5812)
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE /highentropyva- /reference:C:\Path\bin\Release\ProjectB.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.Services.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug:pdbonly /filealign:512 /keyfile:ProjectA.snk /optimize+ /out:obj\Release\ProjectA.dll /target:library /utf8output Properties\AssemblyInfo.cs SomeFile.cs Properties\VersionInfo.cs (TaskId:5812)
Microsoft (R) Visual C# Compiler version 4.0.30319.18408 (TaskId:5812)
(TaskId:5812)
for Microsoft (R) .NET Framework 4.5 (TaskId:5812)
Copyright (C) Microsoft Corporation. All rights reserved. (TaskId:5812)
(TaskId:5812)
SomeFile.cs(32,18): error CS0012: The type 'System.Drawing.Image' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. [C:\Path\ProjectA.csproj]
c:\Path\bin\Release\ProjectB.dll: (Location of symbol related to previous error) (TaskId:5812)
The command exited with code 1. (TaskId:5812)
Done executing task "Csc" -- FAILED. (TaskId:5812)
I was hoping someone here would be able to explain what that was, and how I could reproduce this "bug" with 4.0, however it doesn't look like this question is an easy one to answer.
If I had to guess, I'm going to say that all the references that it can no longer locate are version 2.0.0.0. We had a similar issue here recently where we had to update the references to be for 4.0.0.0 versions of System.* and mscorlib and similar references.
If you cannot replace the references and BindingRedirects aren't an option, try adding v2.0.0.0 manually to your bin folder.
Lastly, you can make your build output verbose to see where it's looking for these references, it might guide you to find a solution.
Perhaps when it updates its not updating your Runtime Settings Schema, specifically the <probing> Element that tells .Net what paths to search for assemblies:
Eg.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;bin2\subbin;bin3"/>
</assemblyBinding>
</runtime>
</configuration>
See: http://msdn.microsoft.com/en-us/library/microsoft.build.tasks.assignprojectconfiguration.onlyreferenceandbuildprojectsenabledinsolutionconfiguration%28v=vs.121%29.aspx
Rachel, any chance references on your System.Drawing on projects are set to SpecificVersion = true after the upgrade?
Also, are you using any precompiled resx files in your library projects?
Try right-clicking the .resx file and choosing 'Run Custom Tool' again to redo the references.
And for last of my attempts to help you, you could try using the useLegacyV2RuntimeActivationPolicy="true" on your main project configuration and try to use the legacy System.Drawing library.

Categories

Resources