TFPT – “An item with the same key has already been added.”

Mar 12, 2016 ALM, General
[Reading Time: 3 minutes]

This day I struggled into an issue with migrating a shelveset from one branch to another. Unfortunately, an error appeared, so I got stuck.

To migrate my shelveset, I use tfpt.exe, that comes with Microsoft Teamfoundation Powertools 2015. So, I first started with typing following command into a developer command prompt:
tfpt unshelve migrate /source:”$/RootProject/SubProject/Branch1” /target:”$/RootProject/SubProject/Branche2” “shelvesetName”

Hint: To get this working, make sure you are calling tfpt.exe from the path, that is the root of you mapped path under beneath. In my case, I would go by “cd” to c:\Projects\RootProject\SubProject\Branch1

Now a dialog appears, that displays all shelveset details.image

From here you can go migrating this by clicking “Unshelve”. The next Dialog, that should appear, should display a bunch of unresolved conflicts, if any. These, you can either merge automatically ore by hand – it’s up to you. In my case nothing happened and console brought up an error – instead of the second dialog, saying “An item with the same key has already been added”. The content of this message is not really descriptive and meaningful… so what is the cause?

First I tried to figure out, where the root cause of this message was, but (honestly) then I felt more and more lazy, doing deep dive, so I considered looking up hints by the use of a Search engine Winking smile.

Here I found several solutions, ranging from adventure, over useless to senseless. But in general – luckily – there were recommendations for undoing pending changes in source (and often also for undoing these in target branch).

I tried some of these hints, but nothing worked. So I played a little bit around and found, that I was that far from a solution with undoing pending changes. It was not only undoing for source and target branch, but it was undoing everything in my Workspace to get that error message away and letting tfpt.exe work as expected.

As a conclusion, be sure, that you first make a “backup” of all pending changes in your workspace, by sending these to a temporary shelveset. Than you can undo all changes and migrate you desired shelveset to the target branche, that you chose before. After successful migration/move, you can restore the “Backup”-shelveset to your workspace. There you are…you moved a shelveset.

By Thomas

I work as a director at CGI in Stuttgart. Responsible for the topic of innovation in the cloud and DevOps, I drive various topics like IoT, AI and Cloud with teams. The agile transformation of German IT companies or ministries plays a major role here, as does the modernization of applications using smart services. For almost two decades I have been supporting as IT architect, developer and coach. I am also very active in the community. As host of Azure Meetup Konstnaz & Region, as well as co-host of Azure Meetup Stuttgart and as co-admin of GitHub Meetup Stuttgart, I would like to share knowledge and experience with like-minded people.

4 thoughts on “TFPT – “An item with the same key has already been added.””
  1. This was the perfect solution when trying to unshelve into a different branch. I had files checked out in other solutions in the Workspace. Once shelved or checked in it worked like a charm. Thank you so much.

  2. Perfect. I wasted lot of time trying to merge my changes with no luck. You saved me another day. Thank you so much.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.