-1

I am given such a warning during visual studio building

7>  No way to resolve conflict between "Microsoft.Extensions.DependencyInjection, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" and "Microsoft.Extensions.DependencyInjection, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60". Choosing "Microsoft.Extensions.DependencyInjection, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" arbitrarily.

In the solution I have several projects. How can I know / find where the compiler's confusion comes from? I was looking everywhere in the solution and I see no assembly in any project where can be used version 2.0.0.0?

Danny Varod
  • 17,324
  • 5
  • 69
  • 111
John
  • 1,834
  • 5
  • 32
  • 60
  • Presumably some library you reference us using the newer version. – ProgrammingLlama Mar 07 '21 at 10:42
  • You may look at transitive dependencies in your projects, some of your libraries can use newer or older version of `Microsoft.Extensions.DependencyInjection` – Pavel Anikhouski Mar 07 '21 at 10:44
  • 1. Check the dependencies of your dependencies, 2. I recommend injecting dependencies via constructors (both as objects for single instances and as factory functions for places where you need to create instances in scope) instead of using a DI library. – Danny Varod Mar 07 '21 at 10:51
  • @John, any update about this issue? – Mr Qian Mar 11 '21 at 05:56

1 Answers1

1

Yes. This may be caused the two nuget package's dependencies which contain the same dependency Microsoft.Extensions.DependencyInjection but different versions. Or it is the project reference's dll.

Like this:

enter image description here

One way is to install Microsoft.Extensions.DependencyInjection nuget package version 3.0.0.

Or add bindingRedirect under xxx.config file:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="xxx" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
        </dependentAssembly>
    </assemblyBinding>
  </runtime>

2) or just find the issue nuget and then update the its version which uses Microsoft.Extensions.DependencyInjection 3.0.0 dependencies.

3) Or you could use PackageReference nuget management format. This is a new nuget management format. Right-click on the packages.config file-->Migrate packages.config into PackageReference.

Besides, if the issue still persists, you could share the packages.config with us to help us troubleshoot the issue in our side.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41