mscorlib version conflict during build

Visual Studio-2013

Visual Studio-2013 Problem Overview


On a new Win8.1 reinstall, with all of my code restored from backup, I'm suddenly now getting a Visual Studio warning when I build the main project of my solution:

> Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.

I set the Output log level to Detailed and I found a few entries like this:

> There was a conflict between "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes". "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" was chosen because it had a higher version.

Trouble is, I'm not referencing mscorlib anywhere in the solution—old or new. I have a couple of apps on my machine that require .NET 3.5, but I can't see how that could be related.

One difference: the old Win8.1 install on which this warning did NOT occur was a standalone machine; this time I'm domain-joined. I don't know whether that makes a difference (I can't see how), but I thought I ought to mention it at least.

Visual Studio-2013 Solutions


Solution 1 - Visual Studio-2013

Having different versions of a Nuget package on different projects may cause this problem as well. Make sure that all your packages have the same version:

  1. (Within Visual Studio) Right click on the solution
  2. Click on Manage Nuget packages for Solution
  3. Click on the Consolidate tab
  4. For every package in the Consolidate tab, update the package to the same version for every project.

Solution 2 - Visual Studio-2013

I was able to fix this by issuing an update-package -reinstall command at the Package Manager Console.

BUT

Be careful, updating all the packages in your solution could cause other problems, make sure you can roll back to a good version if it goes wrong!

Solution 3 - Visual Studio-2013

I have been able to fix this issue by deleting my ".suo" file of my solution and then re-opening the solution. I then rebuild the solution and the issue is gone.

The ".suo" file is within the ".vs" folder which is what I usually delete.

Good luck!

Solution 4 - Visual Studio-2013

I solved this by setting my verbosity to Diagnostic as per this answer.

Once I did that and rebuilt my solution, the build log actually listed the specific packages that depend on the two different versions of mscorlib.

In my particular case, my project had references to version 2.0.20126.16343 of System.Net.Http. I opened up the NuGet Package Manager and updated this package to the latest version (4.3.4 at the time). The next time I built my solution, the warnings were gone.

Solution 5 - Visual Studio-2013

Well my solution is a little bit simpler than all of the above. I simply added a reference to the two Assemblies throwing this error (System.Runtime.Serialization and mscorlib) and rebuilt the project. By doing this, I specified the 4.0.0.0 version and removed the ambiguity.

One of the two (mscorlib) couldn't be added via the GUI because of the "A reference to 'mscorlib' could not be added. This component is already automatically referenced by the build system." error.

I needed to open the .vbproj (.csproj) file and add a reference manually via:

<Reference Include="mscorlib" />

Solution 6 - Visual Studio-2013

I've tried all the following, but none has resolved the issue.

  1. the command "update-package -reinstall".
  2. Update and package via Consolidate tab.
  3. Removing the ".suo" file.

However, My issue was a different case, I guess the new version of Xamarin.Forms package has used a different version of mscorlib. so I've downgraded it and it works fine.

I suggest you try all above solutions and also try to find which package is conflicting.

Solution 7 - Visual Studio-2013

Following Memet Olsen's advice using VS2017 community...almost identical:

  • Right click Solution in Solution Explorer.
  • Select 'Manage Nuget Packages for Solution'
  • Check the packages. If any of them have a blue up-arrow rather than a green tick use the 'update' button

Solution 8 - Visual Studio-2013

I also have tried all of the proposed solution to no avail.

In my project, this warning message was caused by a dll reference having a dependency on a different .net framework than the one that is targeted by my project.

In order to find out which dll reference was causing the warning, I simply used .net reflector to explore each dll reference to find out which one was referring a different .net framework (mscorlib).

In order to fix the issue, the reference dll has to be updated to a version which targets the same .net framework as the project using it, if such a version exist.

Hope this helps.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionInteXXView Question on Stackoverflow
Solution 1 - Visual Studio-2013Memet OlsenView Answer on Stackoverflow
Solution 2 - Visual Studio-2013InteXXView Answer on Stackoverflow
Solution 3 - Visual Studio-2013JacobView Answer on Stackoverflow
Solution 4 - Visual Studio-2013Stephan BView Answer on Stackoverflow
Solution 5 - Visual Studio-2013Garet JaxView Answer on Stackoverflow
Solution 6 - Visual Studio-2013Ahmed El-ArabyView Answer on Stackoverflow
Solution 7 - Visual Studio-2013PaulustriousView Answer on Stackoverflow
Solution 8 - Visual Studio-2013Sup3rHughView Answer on Stackoverflow