Conflict of versions after upgrading to .NET 6 with ServiceCollection
Asked Answered
W

2

11

Upgrading from .NET 5 to .NET 6 is proving not so straightforward as I expected.

All my unit test projects fail to compile due to the following error

Severity    Code    Description Project File    Line    Suppression State
Error   CS0433  The type 'ServiceCollection' exists in both 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' and 'Microsoft.Extensions.DependencyInjection, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'    Sample.DynamoDb.FunctionalTests C:\src\my-solution\test\Sample.DynamoDb.FunctionalTests\DependencyInjectionTests\GetServiceTests.cs 22  Active

They reference class libraries that depend on Microsoft.Extensions.DependencyInjection.Abstractions version 6 but for some reason it seems there is a dependency on Microsoft.Extensions.DependencyInjection in the test project itself. Probably dragged across by some of the packages I use (and I don't know which one).

This is my test project

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <Nullable>Enable</Nullable>
        <IsPackable>False</IsPackable>
        <IsPublishable>False</IsPublishable>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="FluentAssertions" Version="6.2.0" />
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />

        <PackageReference Include="xunit" Version="2.4.1" />
        <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
            <PrivateAssets>all</PrivateAssets>
        </PackageReference>
        <PackageReference Include="coverlet.collector" Version="3.1.0">
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
            <PrivateAssets>all</PrivateAssets>
        </PackageReference>
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\..\src\Sample.DynamoDb.DependencyInjection\Sample.DynamoDb.DependencyInjection.csproj" />
    </ItemGroup>

</Project>

Anyone with a similar problem or an idea on how to troubleshoot and find the issue or a workaround?

With answered 9/11, 2021 at 14:56 Comment(7)
And csproj for Sample.DynamoDb.DependencyInjection?Permute
Solved, see my answer. Thank for your time!With
Should we guess - you didn't upgrade the packages in Sample.DynamoDb.DependencyInjection.csproj? Or the test project?Auspex
I did upgrade all packages, but it turns out some third party dependency had a dependency on microsoft logging 5.0.0. It's now SOLVED. Thanks!With
Please do not answer the question within the answer post. I've rolled back those edits. Use the answer posts, which it looks like you've now done.Telethon
May I ask what you did to solve the problem?Gildea
@JanHansen see my answer below. Also this may help troubleshooting https://mcmap.net/q/734207/-could-not-load-file-or-assembly-newtonsoft-json-when-running-app-from-the-dotnet-publish-output-folderWith
W
9

It turns out the problem was because some referenced project, referenced another, that referenced another... that had a nuget dependency EventStore.Client.Grpc that depends, itself, on Microsoft.Extensions.Logging 5.0.0

And that Microsoft.Extensions.Logging bring the subdependency Microsoft.Extensions.DependencyInjection 5.0.0

Having a look at my test project's obj/project.assets.json helped me trace that.

With answered 9/11, 2021 at 15:28 Comment(0)
A
1

I was able to resolve this issue by explicitly installing the nuget package:

Microsoft.Extensions.DependencyInjection 8.0.0

Actinoid answered 16/11, 2023 at 12:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.