Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly uses version X which has a higher version than referenced assembly error

After upgrading from ASP.NET Core 2.0 to 2.1-preview2 I got the following error:

Error   CS1705  Assembly 'System.Data.SqlClient' with identity 'System.Data.SqlClient, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' uses 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime' with identity 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

When I look around for similar errors, I see a lot of discussions about the versions that are referenced in csproj or json files (depending how old the discussion is). But in .NET Core there is only one reference to Microsoft.AspNetCore.App. So, I don't have any way to manipulate the references to either System.Data.SqlClient or System.Runtime

Another observation that while most errors refer to real code like connection.Open() there are two references to non-existent file CSC line 1.

UPDATE: if I create a new project and copy the offending code there, I am not getting any errors. So, apparently the references to the mismatching versions are somewhere in the project... but I can't figure out where!

like image 819
Felix Avatar asked Apr 19 '18 20:04

Felix


People also ask

Has a higher version that the referenced assembly?

This error indicates that there is a version mismatch between what is referenced by the assembly (<Y.Y.Y.Y>) and what the project is pointed towards (<Z.Z.Z.Z>). To correct this, you need to re-add the correct reference in Solution Explorer. Confirm that the DLL version <Y.Y.Y.Y> is present on your computer.

How do you fix referenced assembly does not have a strong name error?

Step 1 : Run visual studio command prompt and go to directory where your DLL located. Step 2 : Now create il file using below command. Step 3 : Generate new Key for sign your project. Step 4 : Now sign your library using ilasm command.


2 Answers

Had the same issue. Resolved by locating RuntimeFrameworkVersion tag in .csproj file and changing it's value to 2.1.

like image 107
Marko Avatar answered Sep 30 '22 21:09

Marko


Using Visual Studio, the easiest way is:

1.- Right-click on the solution and go to "Manager Nugget Packages for solution..."

2.- Go to "Consolidate tab" (The last on the right side) You will see the different versions of assemblies on each project.

  • Try to unify the version for all project references within your solution. (Uninstall and install the same version).

Good Luck!!

like image 43
David Castro Avatar answered Sep 30 '22 21:09

David Castro