VS 2015 Multiple assemblies with equivalent identity have been imported - c#

One of my project solution is working fine on a system where I have installed VS 2013. But When I open the same project on another system in VS 2015 it is giving this reference error:
Error CS1703 Multiple assemblies with equivalent identity have been imported: 'D:\src\packages\Microsoft.Bcl.1.1.10\lib\net40\System.IO.dll' and 'C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5\Facades\System.IO.dll'. Remove one of the duplicate references.
The project file is referencing the package file, but when it opens in VS it auto converts to Framework library path. I can't uninstall the BCL package because it is a dependency for other packages.
Edit:
Why does the solution build fine in one version of Visual Studio but it gives the multiple assemblies error in another version?
Is there a way to resolve this issue so that it works in different versions?
I also have this issue however his solution builds perfectly in VS 2017 but it cannot build on VS 2015.

This error usually appears when a NuGet package has invalid dependencies, but this is not the case as everything works well in other versions of Visual Studio.
First you can force reinstall all NuGet packages. That can be done by opening the Package Manager Console and typing:
Update-Package -reinstall
Second most common solution to this problem is to ensure Visual Studio is updated to the latest version (Visual Studio 2015 Update 3 in this case). If that doesn't help, please try reinstalling Visual Studio completely on that device. Finally - you can try to install Visual Studio 2015 on another PC to verify if this is actually a problem of that version, or a PC-specific issue.

This error occurs when a non-portable library references to a portable library then the build system adds a facade assemblies. [1]
Try to remove following references:
<Reference Include="System.IO">
<HintPath>..\packages\System.IO.4.0.10-beta-22516\lib\net45\System.IO.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System.Text.Encoding">
<HintPath>..\packages\System.Text.Encoding.4.0.10-beta-22516\lib\net45\System.Text.Encoding.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Threading.Tasks">
<HintPath>..\packages\System.Threading.Tasks.4.0.10-beta-22516\lib\net45\System.Threading.Tasks.dll</HintPath>
<Private>True</Private>
</Reference>

If you are using a common assembly across multiple projects and want to ensure they are using the same version, I recommend installing that version into the Global Assembly Cache.
Then that version from the GAC will be available from the references dialog.
Use that same dialog for the references across assemblies.

Related

Reference not updated after install

I have recently upgraded my reference packages
Microsoft.Aspnet.Mvc from 4.0.0 to 5.0.0,
Newtonsoft.Json to 6.0.3,
Microsoft.Aspnet.WebApi to 5.0.0
And I installed it using NuGet Package Manager Console in Visual Studio 2013. But when I check the version of the references in the solutions explorer, I still see the older version for MVC reference. The other references have been updated.
In the .csproj file I see the Reference include for System.Web.Mvc mentions version 4.0.0.0 but HintPath is for 5.0.0.
I tried the following:
Deleted the packages directory from Windows explorer
Updated package through Package Manager Console, but the problem still persists.
Could someone help me with this?
Edit: Adding one of the reference tags
<Reference Include="System.Web.Mvc, Version=4.0.0, Culture=neutral, PublicKeyToken=12345, processorArchitecture=MSIL">
<SpecificVersion>false</SpecificVersion>
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.0.0\lib\net45\System.Web.Mvc.dll</HintPath>
</Reference>
As you can see, the Version in the reference is 4.0.0 and that in the hint path is 5.0.0. 4.0.0 is the version I see in the solution explorer.
I also set the specific version tags to True for all the references in question and built the code, but again, when I look at the properties of the reference in solution explorer, I see 4.0.0.
Edit 2: I deleted the reference from the solutions explorer, then References >Add References > Browse> Selected the latest downloaded Reference dll from package directory. The version in reference manager is 5.0.11001.0
Then I looked at the properties of the added reference. It still is 4.0.0

Azure DevOps Build missing assembly reference

I have a build process on Azure DevOps that I have been building successfully for awhile now.
Recently one of my developer added a page that contains the MVC library
using System.Web.Mvc
However, the build keeps failing now when I build it via the Azure DevOps build agent as part of our CI/CD process.
ClassName.cs(5,18): Error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
It compiles if I compile manually using Visual Studio 2017 on my own laptop or if I use the Visual Studio 2017 on the build machine where the Azure DevOps build agent runs.
The steps that I've tried to troubleshoot:
Ensure in my Project's NuGet, that I have Microsoft.Aspnet.MVC latest
vesrion.
I've tried to reinstall Microsoft.Aspnet.MVC on the build
machine through NuGet
I verified my project' default package
management format is : Packages.config
I verified that my
packages.config has < package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net472" />
I tried to reinstall all
the package on my build machine by running Update-Package
--reinstall command.
I verified that on the build agent machine I have the Microsoft.AspNet.Mvc folder and all of its dlls under repositoryPath -
$(Solutiondir)/packages and globalPackagesFolder -
$(UserProfile).nuget\packages
I'm running out of idea on why it compiles on Visual Studio manually but has error when I compile using the build agent through MS Build on x64 bits.
I have tried to reproduce your bug by comparing two new ASP.NET Web Application (.NET Framework) projects, one created with an empty template and the other with the MVC template. The MVC project comes with the System.Web.Mvc reference and the empty one does not, so I have come up with additional troubleshooting steps while manually adding the reference to the empty project.
Make sure the project file that is failing to build includes a reference to the Microsoft.AspNet.Mvc package which includes a path (use your latest version)
<Reference Include="System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.2.4\lib\net45\System.Web.Mvc.dll</HintPath>
</Reference>
You can copy this and it from a newly created MVC template. An implicit reference <Reference Include="System.Web.Mvc" /> will only work if build artifacts were generated before which could be a good reason for a build succeeding in development and failing in the build pipeline.
Clean the solution, close Visual Studio and delete all bin and obj folders to make sure your build is not succeeding because of previous ones and Visual Studio does not regenerate them.
Use the Developer Command Prompt to call msbuild.exe in the project folder, this will be a more similar environment to your build pipeline than building with Visual Studio

How to change a nuget packet assembly version

In Visual Studio with my Asp.net core project, I have used some nuget packets (like StackExchange.Redis, Serilog etc..). I decided to use Visual studio 2019. Everything was going well, but one day I noticed some projects couldn't update their referenced projects in solution. Because they are (.net standard libraries) taking output codes to obj folder instead bin folder.
I decided to return Visual Studio 2017. Everything working great with VS2017, but this time it giving me a run time error such as could not found referenced assembly public key etc.. like below
I have removed old pockets from all projects in the solution by the package manager nuget manager. I have installed a new version by the nuget manager tool. But project always seemto be using the old version.
FileNotFoundException: Could not load file or assembly 'StackExchange.Redis, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c219ff1ca8c2ce46'. The system cannot find the file specified.
For example, if I install a nuget packet version 2.0.0.0 and I want to remove it all from project and I want to install a new version by an upgrade or downgrade. What should I do? How can I change it?
Update: I have uninstalled 2 packages from nuget and from windows, still project seen this assemblies!
Severity Code Description Project File Line Suppression State
Error CS0433 The type 'ConnectionMultiplexer' exists in both
'StackExchange.Redis.StrongName, Version=1.2.6.0, Culture=neutral,
PublicKeyToken=c219ff1ca8c2ce46' and 'StackExchange.Redis,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=c219ff1ca8c2ce46' Tursys.Pool.Storage.Api D:\projects\tursys\PoolStorage\src\Tursys.Pool.Storage.Api\Startup.cs 76 Active
Both of them not exist
You can try it:
Install-Package "YourProjectName" -Version 6.2.0
Answering my own question, for anyone:
VS-2019 corrected it's output folder as bin folder with a new bug-fix! but it was not related with the nuget package removement problem
How to remove a package from a project:
In Visual Studio i want to go to file with F12 key. And with the open target folder command i see the local folder of the removed package as
C:\Users\HAMIT\AppData\Local\Temp\MetadataAsSource\821e7bd605414042826501fe0b5cdc21\32ae5450ea724e84b62f983bdb6bb879
I have deleted this temp files but by the rebuild process VS restored them again. This some bored me and i found a new manner. There is always a technic to removing a package from the VisualStudio with the -force argument like below in PM Console
Uninstall-Package -ProjectName "YourProjectName" -RemoveDependencies -Force
When you put this command it will asking you the PackageId will be removed. Write your package name and it is ok!
If you dont know your package name exactly then you can get a list according your project like below:
Get-Package -ProjectName "YourProjectName"
But uninstalling to StackExchange.Redis.StrongName still is enigma!!!
UPDATE: I found a solution for this too! Change Aspnetcore framework 2.2 to 3.0 under Visual Studio 2019. Now seem to right dlls and Everything corrected.

Xamarin in VS - Unable to install Android Support v4

I installed Visual Studio 2015 to try out Xamarin that comes with the community version, but I have not been able to open a single project. I have downloaded a few projects from GitHub that I want to try out, but they all get the same error. First, it says I am missing a reference/assembly, and I figured this was the Xamarin.Android.Support.v4. So I downloaded this from Xamarin's website and added it to the project. This somewhat worked, however every time I try to build my project, I get an error:
NuGet Package restore failed for project AndroidAltBeaconLibrary.Sample: Unable to find version '21.0.3' of package 'Xamarin.Android.Support.v4'.
This error seems to haunt me whatever I try to do. When I open my NuGet manager, I am not able to do anything, as this error pops up here as well (I wanted to try remove the NuGet and add it again). It just says Xamarin.Android.Support.v4 is installed (but not available in this source) regardless of if I remove it from References.
Does anyone have any tips of what to do??
Edit: I forgot to mention, the version I downloaded is 23.1.1.1
Edit 2: Using the install command does not work in the projects. An error says it needs to restore NuGet packages first, however it is not able to do this either. In a blank project, it is not able to find this NuGet (neither 23.1.1.1 nor 21.0.3.. In fact, when I open NuGet manager, it is not able to find any NuGets at all in the Browse Tab. Is my VS just messed up? Should I reinstall the whole thing??
I have trouble restoring Xamarin.Android.Support nugets too. This solved my issue:
1) allow nuget restore on build (Tools > NuGet Package Manager > Package Manager Settings)
2) remove the reference from .csproj file:
<Reference Include="Xamarin.Android.Support.v4, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Xamarin.Android.Support.v4.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v4.dll</HintPath>
<Private>True</Private>
</Reference>
3) rebuild all (ignore errors, restore will still work)
4) put the reference back to .csproj file
5) rebuild and it should be OK
You need to use the specific 21.0.3 version of Xamarin.Android.Support.v4, which Xamarin uses.
Install it from NuGet

Nuget references in Visual Studio

I had the solution in VisualStudio 2012 with some nugets packages installed with chosen version by me. After migrating to VisualStudio 2013 I find out that packages are referenced from hard drive instead of nuget.
In nuget I installed WindowsAzure.Storage, version 3.1.0.1.
After migration there is WindowsAzure.Storage referenced from hard drive, version 3.0.3.0.
In project .csproj file I have:
<Reference Include="Microsoft.WindowsAzure.Storage, Version=3.1.0.1, ...>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\WindowsAzure.Storage.3.1.0.1\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
</Reference>
I can see that nuget didn't set SpecificVersion to true, so VisualStudio is using version it found on hard drive instead of downloading one from nuget.
Is there any way to change it without some nasty hacks so it will always download dlls from nuget if package was installed by nuget.
How about restoring all your packag:
NuGet Package Restore

Categories