Skip to content

Grpc.Net.ClientFactory in unit test causing exception after upgrade to .Net 6.0: The type 'ServiceCollection' exists in both 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' and 'Microsoft.Extensions.DependencyInjection, Version=3.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' #1481

@ncipollina

Description

@ncipollina

What version of gRPC and what language are you using?

<PackageReference Include="Grpc.Net.Client" Version="2.40.0" />
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.40.0" />
C#

What operating system (Linux, Windows,...) and version?

Windows 10

What runtime / compiler are you using (e.g. .NET Core SDK version dotnet --info)

.NET 6.0.100

What did you do?

We had a Unit Test project that we upgraded from .Net 5.0 to .Net 6.0 where we were unit testing a IServiceCollection extension method to inject a gRPC client to the dependency injection container. The unit test in question looks like the following:

        [Fact]
        public void AddNotificationSystemClient_NullAction_ThrowsException()
        {
            var s = new ServiceCollection();

            Action act = () => s.AddNotificationSystemClient((Action<NotificationSystemOptions>)null);

            act.Should().Throw<ArgumentNullException>();
        }

The issue is that Grpc.Net.Clientfactory 2.40.0 has a reference to Microsoft.Extensions.Http 3.0.3 which causes the following error when building.

The type 'ServiceCollection' exists in both 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' and 'Microsoft.Extensions.DependencyInjection, Version=3.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'

What did you expect to see?

I expected to be able to compile and run the unit test.

What did you see instead?

When building the project, I get the following build error:

The type 'ServiceCollection' exists in both 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' and 'Microsoft.Extensions.DependencyInjection, Version=3.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'

Anything else we should know about your project / environment?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions