none
Updating NuGet package fails with "Error: An item with the same key has already been added"

    Question

  • In recent weeks I've been noticing an issue with a couple of our solutions, when trying to update or remove NuGet packages:

    It also fails if I use the console:

    I'm at a loss to know where to look. I came across an article that suggested looking in each package.config files to see if the same package might be listed twice, but they are all fine. Another article suggested removing all packages and reinstalling, but I'd rather not go down that route if I can help it.

    Any ideas what else to check?


    Wednesday, November 09, 2016 11:26 AM

All replies

  •  Hi Andy,

    Welcome to the MSDN forum.

    Refer to your description, I tried to create a new project and install a previous NewtonSoft.Json package through Nuget Manager Console, then use the same command: update-package NewtonSoft.Json to update and it successfully upgraded to the latest version 9.0.1 version like the following screenshot, could you please test it on a new project and see if this issue is relating to those specific solutions or not.

    If this issue is prefer to those specific solutions, per the error message “An item with the same key has already been added”, please have a look at this similar issue and have a try with the following to troubleshot this issue:

    1. Reopen VS and reload this project and clean, rebuild your solution
    2. Update Nuget, please go to Tools—Extensions and updates… and if there is update for Nuget Package Manager, please install it then reopen VS.
    3. Check Solution Explore--References and the file ‘packages.config’, the folder ‘packages’ that under root folder of the solution store folder, if there are different versions for the same packages, remove them then modify the package.config file to use the latest version.
    4. Under Solution Explore and click “Show All Files” icon and check the bin folder, see if there is any reference to the .dll that you try to install/update through Nuget or not. Remove it once you found.

    Best regards,

    Sara


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 10, 2016 7:26 AM
    Moderator