nuget reference package version conflict

Viewed 25

Type “ServiceCollection” Both exist in “Microsoft.Extensions.DependencyInjection.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60” and “Microsoft.Extensions.DependencyInjection, Version=5.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60”.

Please guide how to correct this so that there won’t be any conflicts between versions of the same assembly within the solution and the same assembly reference will be used in all the projects.

2 Answers

uninstall 2 packages from all projects in solution and select one of them in the solution. if you found other required in depended solution try remove this dependece and replace by other

Funny (not really), the class ServiceCollection was moved from Microsoft.Extensions.DependencyInjection to Microsoft.Extensions.DependencyInjection.Abstractions in the version 6 :

Move ServiceCollection to abstractions (#52284)

Consequently the library Microsoft.Extensions.DependencyInjection isn't retrocompatible between the version 5 and the version 6.

In your case, you have a project that reference "Microsoft.Extensions.DependencyInjection.Abstractions" at the version 6, but also reference "Microsoft.Extensions.DependencyInjection" at the version 5, but as explained below this two versions aren't compatibles. You need to consolidate this two references.

If your project references directly the two references, just uninstall "Microsoft.Extensions.DependencyInjection.Abstractions" (as "Microsoft.Extensions.DependencyInjection" reference it).

But if this references are transitions, you can open the file "obj\project.assets.json" to try find where they come from. Then you can update some packages to consolidate its.

Related