Chew Hong Yu
Chew Hong Yu

Reputation: 187

The type 'ServiceCollection' exists in same dependencies but in different version

The error description is as below:

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.1, Culture=neutral, PublicKeyToken=adb9793829ddae60'

I am having this error suddenly, I had tried several steps but the error wont go off. Some steps that I had tried:

  1. Unload and reload project
  2. Clean and rebuild solution
  3. Delete obj and bin folder and rebuild solution once again

Someone know how to solve this issue?

Error Image

Upvotes: 12

Views: 6884

Answers (2)

Svetlana
Svetlana

Reputation: 149

Add this line to your project:

<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />

It helped me.

Upvotes: 14

Reece Gibbs
Reece Gibbs

Reputation: 46

The comment on the original post was really helpful

I had the same issue and managed to resolve it by targeting .NET 6.0

Probably best to ready ourselves to point all of our .NET 5.0 projects to .NET 6.0 anyway since .NET 5.0 is being deprecated

Upvotes: 3

Related Questions