Skip to content

"An item with the same key has already been added" - when project graph has projectName == packageRef name (of same version) #6795

Closed
NuGet/NuGet.Client
#3789

Description

@ceddlyburge

The problem occurs when a dll is referenced as a nuget package and as a project reference.

If there are 3 projects, Source, Intermediate and DoublyReferencedTarget

Then the problem will occur when Source has:

  • ProjectReference to project Intermediate
  • ProjectReference to project DoublyReferencedTarget

And 'Intermediate' has

  • PackageReference to project DoublyReferencedTarget.

Thus project DoublyReferencedTarget is referenced twice in two different ways, which creates this error.

I realise that this is a genuine error, but a better error message would be very useful. Some of our solutions contains 100's of projects (a bad idea I know), and it's just taken me a week to track down this problem.

I have created a repo to demonstrate the problem at https://github.com/ceddlyburge/nuget-error.

Activity

  1. added
    Area:ErrorHandling
    on Apr 9, 2018
  2. nkolev92 commented on Apr 17, 2018

    @nkolev92
    Member

    @ceddlyburge
    I am unable to reproduce this with the latest 15.7 preview.

    Which version of VS are you using?

  3. laszlohorvath commented on Apr 19, 2018

    @laszlohorvath

    I am able to reproduce it with the demo repo. VS 2017 Ent 15.6.6

    And we also have this issue, and it is a quite big problem here, I've spent days to solve it, but we were unable to. So any help (hotfix, workaround, etc...) would be appreciated.

  4. ceddlyburge commented on Apr 19, 2018

    @ceddlyburge
    Author

    Hi there, I am on VS 2017 Professional 15.6.4

    I also get the problem on the command line using nuget 4.3.0.4406, which in turn uses msbuild 15.6.82.30579

  5. MisterJimson commented on Nov 2, 2018

    @MisterJimson

    Running into this as well...

  6. natemcmaster commented on Nov 9, 2018

    @natemcmaster

    Ran into this as well with VS 15.9. Anyone found a solution?

  7. JosepBalague commented on Feb 7, 2019

    @JosepBalague

    NuGet 4.9.2.5706 (nuget restore), msbuild version '15.9.21.664', VS2017 15.9.6 still failing. When this will be solved?

  8. bdongus commented on Apr 6, 2019

    @bdongus

    Nuget 4.9.3.5777, VS2017 15.9.11. This still is an issue.

  9. thyn commented on Apr 25, 2019

    @thyn

    vs19 same issue

  10. GraySerg commented on Jul 8, 2019

    @GraySerg

    VS 2019 same error

  11. ivankarpey commented on Jul 8, 2019

    @ivankarpey

    This is insane to see such a problem exist for such a long time without any response or workaround provided by the Nuget team. As I still could confirm these issues exist (vs 2019, .net core 3.0 preview) the simple workaround is to change the version of a package you do reference in sources. With the new version, it should start working fine.

  12. zivkan commented on Jul 10, 2019

    @zivkan
    Member

    I was able to reproduce the error. The exception is thrown here: https://github.com/NuGet/NuGet.Client/blob/3113c5ddf420ae0c9c34959108e127136c8f141e/src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs#L152

    The issue appears to be that the same name+version pair is both a package and a project reference. If they had different versions, it would work, or if it was consistently a package or a project reference both times, I expect it would work.

    My initial reaction is that the assets file might need to change to support this scenario, rather than being a simple bug to fix.

  13. 47 remaining items

  14. nkolev92 commented on Feb 4, 2021

    @nkolev92
    Member

    @erdembayar
    Given that it's an implementation detail and a question to the team, let's continue the discussion on the PR instead.

  15. added
    Category:Quality Week
    on Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area:ErrorHandlingCategory:Quality WeekFunctionality:RestorePriority:2Style:PackageReferenceType:Bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions