Home > Net >  Multiple dependencies conflict in ASP.NET Core 3.1 and 6.0 ServiceCollection exists in both
Multiple dependencies conflict in ASP.NET Core 3.1 and 6.0 ServiceCollection exists in both

Time:04-28

enter image description here

Is there any way to see where the v6 reference is coming from? I have searched for 6.0, checked nuget package references (all 3.1.x)

I can see this issue is only limited to a couple of projects in the solution, but running out of ideas of things to check.

This project uses some base project, via a gitlab nuget repo, and itself builds nuget packages to be consumed again, if that is relevant. The base projects do not exhibit this issue (I have added ServiceCollection to each one, and all resolve to 3.1.15 version when pressing F12).

F12 in this project resolves to v6.0:

v6.0 resolution

but I have no idea why or how to change it.

CodePudding user response:

As expected, there was a reference to .NET Core v6.0 somewhere in the hierarchy chain. However, I did not have an easy way to find it.

Having found a project with the issue, the project file had two sections, the nuget references and project settings. I commented out various sections and rebuilt. Yes, there was multiple more errors as packages/projects were now missing their reference, but crucially I was looking for the error above to disappear. The culprit was one of my base projects, so off to the base solution to continue the investigation.

While it was not needed, I added a line of code ServiceCollection sc to the projects, and worked out which one caused an error. I was able to replicate that error in a couple of projects and followed the same process. I commented out various lines in the project file until I made that error go away. (yes there were many, many more errors, but the absence was the key.

It turned out to be a reference to AutoMapper Dependency Injection v11, which has a dependency on Options v6.0.0!

It would be nice to have a way to trace the source of references as even viewing the AutoMapper refence in the main projects did not show its dependency on the DI part.

Hope it helps someone and saves some time.

  • Related