Click here to Skip to main content
15,886,199 members
Articles / DevOps
Tip/Trick

Resolve version error (CS1705) through Package Manager Console

Rate me:
Please Sign up or sign in to vote.
1.00/5 (2 votes)
22 Mar 2019CPOL2 min read 21.4K   1  
How to handle 'Which has higher version than referenced assembly' error (Error CS1705) through Package Manager Console

Introduction

Where there are multiple project within the solution and one project is dependent on other, and versions introduce breaking changes, we sometimes encounter package version conflict and Visual Studio solution does not build. It may return the following error:

Error    CS1705    Assembly 'WebAPI' with identity 'WebAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' which has a higher version than referenced assembly 'Microsoft.AspNetCore.Mvc.Core' with identity 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'    WebApiTest    C:\... 
 

The above error can be produced on a solution that uses two projects, namely WebApi and WebApiTest. 

Background

The error above shows that the test project and API project are using a different version of Microsoft.AspNetCore.Mvc.Core. For example, the test project is using version 2.1.0.0 while the API project is using 2.1.1.0.

We can resolve this issue by updating the package reference in either of the projects to match. For example, we can update the WebApiTest project to use the higher version of the assembly (i.e., at 2.1.1.0) or downgrade the assembly version in the WebApi project to 2.1.0.0 depending on the need.  
 

Resolution Example

We can issue a command like below in the package manager console targetting the right project. For example, the code below will update the assembly reference for Microsoft.AspNetCore.Mvc.Core on WebApiTest test to use version 2.1.1.0. This will then match the version of the same assembly in the WebApi project.  The following code 

C++
Install-Package Microsoft.AspNetCore.Mvc.Core -Version 2.1.1.0 -ProjectName WebApiTest 

The argument '- ProjectName WebApiTest' name can be omitted if the correct project is selected in the dropdown that is available in the Package Manager Console window in the Visual Studio. An example of screen shot is shown in the figure below:

Package Mangager Console window in Visual Studio 2017 running on Windows machine.

Figure: Package Manager Console window in Visual Studio 2017 running on Windows machine.

Likewise, to update the WebApi project instead, the following command will do the trick:

C++
Install-Package Microsoft.AspNetCore.Mvc.Core -Version 2.1.1.0 -ProjectName WebApiTest 

 

History

03/21/2019. Added an image of a package manager console.

03/20/2019. First Commit

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
United States United States
Benktesh is a senior software engineer at Sony where he is a software developer/architect. His main focus when coding is quality, simplicity, and scalability and he is experienced in a broad range of subjects (software design, software development process, project management, testing, UI, multithreading, database, mobile development, and more).

Outside of professional work, there are always some side projects he is working on such as simulation modeling of financial, energy and emissions data and writing articles both technical and non-technical (see his blog at https://benktesh.blogspot.com/). While not coding, he is either reading books fiction and/or non-fiction, watching tv shows, trading stocks, and discussing climate change, global warming, emission trading, and traveling to meet people, place, and culture.

Comments and Discussions

 
-- There are no messages in this forum --