VMware Cloud Community
alexbenetatos
Contributor
Contributor

An item with the same key has already been added.

I'm trying to create a new VM using the command:

get-vmhost [esx_server_name] | new-vm -name [vm_name] and get the following error:

New-VM : 10/01/2011 16:22:57    New-VM        An item with the same key has already been added.

   + CategoryInfo          : NotSpecified: (:) [New-VM], VimException
   + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

I'm using Powershell v2 and Powercli 4.1.1 and my VMware environment is vSphere 4.0 U1

My code was working fine previously, so I'm just wondering if anyone come across this particular error before?

Many thanks

Tags (2)
0 Kudos
24 Replies
admin
Immortal
Immortal

Outputting the stack trace can't solve the issue - it's simply coincidence. I guess the issue appears from time to time depending on something happening on the server - not sure what that is though.

0 Kudos
clintonskitson
Contributor
Contributor

I ran into this issue when trying to create a snapshot of a VM.  It only happens on the first occurence of a command in a new PowerCLI session after I close out another session.  The quick fix can be to do something like the following..  You can repeat the first command against PowerCLI, first in the try block with a "-ea stop" which properly signals a stop exception and will then run the catch block to run the command again.

if($vm | get-snapshot | where {$_.name -eq "arraysnap"}) {
    write "Removing Previous VM Snapshot .."
    try {
        Write "Trying to remove snap.."
        $vm | get-snapshot | where {$_.name -eq "arraysnap"} | remove-snapshot -confirm:$false -ea stop| out-null
    } catch {
        Write "Encountered PowerCLI bug.. trying again.."
        $vm | get-snapshot | where {$_.name -eq "arraysnap"} | remove-snapshot -confirm:$false | out-null
    }  
}

infinitesorrow
Contributor
Contributor

I've been getting this error intermittently before as well, but now it has come to stay, it seems. I'm using vCloud Director 1.5.

I'm using the VcloudSDK_V1_5.dll in .NET, and are getting it when calling the com.vmware.vcloud.sdk.Vdc.GetVdcByReference(vCloudClient client, ReferenceType vdcRef) method. Now, this seems to happen only to one user (I log him in in the API, and then I can't get the Vdc). This code has worked before for this user. The only thing that's happened (that I can remember) is that I changed ownership of a vApp from me to him. Now this call fails.

The stack I have at the moment is:

com.vmware.vcloud.sdk.utility.VCloudException: An item with the same key has already been added.

at com.vmware.vcloud.sdk.Vdc.GetVdcByReference(vCloudClient client, ReferenceType vdcRef)

[..]

my code

I saw something about an upgrade in an earlier post from you, is there a later version for the .DLL as well, or do we need to upgrade on the servers?

Thanks!

0 Kudos
infinitesorrow
Contributor
Contributor

I tried pulling the InnerException property from the VCloudException that I catch, but it's null - so that's the best call stack I have..

0 Kudos
infinitesorrow
Contributor
Contributor

Ok, so I changed ownership of the vApp in vCloud back to me, and all of a sudden, the user could login again without the error.

It also only happens in the API DLL. If I use the vCloud gui for the user, it worked just fine. Still need to know why though, if this happens every time ownership changes - we're not going to be able to use the APIs..

0 Kudos