20

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!

Felix
  • 9,248
  • 10
  • 57
  • 89
  • It looks like the `System.Data.SqlClient` assembly has a dependency on assembly `System.Runtime, Version=4.2.1.0`. Your project is using assembly `System.Runtime, Version=4.2.0.0`. – JuanR Apr 19 '18 at 20:56
  • ok. and? can I fix it? I don't include either one explicitly; just `"Microsoft.AspNetCore.App" Version="2.1.0-preview2-final"` – Felix Apr 19 '18 at 21:42
  • Look at the target .NET Framework for the project. That is why a new project works out of the box. – JuanR Apr 20 '18 at 00:28
  • It's 2.1 for all – Felix Apr 20 '18 at 14:43

2 Answers2

8

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

Marko
  • 1,502
  • 5
  • 21
  • 40
  • 4
    I also had the same issue, but a different cause. I was incorrectly including a library 'Z' targeting dotnet core 2.1 into a library 'Y' targeting dotnet standard 2.0, that was included in the final app 'X' targeting dotnet core 2.1. The compiler really didn't like this, but the error messages was cryptic, (the same as in original question). Refactoring the 'middle' library in the chain ZYX to dotnet core 2.1 fixed it. I realize this sounds obvious, but I was given Z and Y and they all worked on their own. Your question has only one library, I post this for others who may have this problem – JimbobTheSailor Dec 06 '18 at 01:16
  • 1
    for core 2.2.1 change this to 2.2 – Nouman Bhatti Dec 11 '18 at 00:58
1

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!!

David Castro
  • 1,773
  • 21
  • 21
  • Thanks, David. It was a single-project solution; so your suggestion doesn't apply. Anyway, the issue is 3.5 years old and we solved it by creating a new project and just moving code as I indicated in the update. Probably a bug in Microsoft's beta version – Felix Sep 06 '21 at 18:35
  • 1
    Actually, it happened to me in the morning and that's why I posted the solution that helped me out to solve the issue. ;) – David Castro Sep 06 '21 at 22:15