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'
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 835
- Avg merge
- 6d 3h
- Merged PRs (30d)
- 7
Description
### What version of gRPC and what language are you using?
``
``
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:
```csharp
[Fact]
public void AddNotificationSystemClient_NullAction_ThrowsException()
{
var s = new ServiceCollection();
Action act = () => s.AddNotificationSystemClient((Action)null);
act.Should().Throw();
}
```
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?
Contributor guide
Research direction
Start with the shown unit test and the PackageReference entries for Grpc.Net.Client and Grpc.Net.ClientFactory 2.40.0, then inspect the resolved Microsoft.Extensions dependency versions in the .NET 6 build. Confirm the fix by compiling and running the test without the duplicate ServiceCollection error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- build-system, testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100