diegosasw
diegosasw

Reputation: 15634

Conflict of versions after upgrading to .NET 6 with ServiceCollection

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?

Upvotes: 11

Views: 5191

Answers (2)

milorad
milorad

Reputation: 131

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

Microsoft.Extensions.DependencyInjection 8.0.0

Upvotes: 1

diegosasw
diegosasw

Reputation: 15634

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.

Upvotes: 9

Related Questions