Thursday, January 17, 2013

Failed to install key pair — Object already exists error

The problem is that you cannot delete a key and you cannot add the key. This is because you do not have access to the key to delete it and the .NET framework cannot add it because of constraints on the StrongName data store.


The solution is to give yourself access to C:\Documents and Settings\AllUsers\ApplicationData\Microsoft\Crypto\RSA\MachineKeys\. This allows proper functioning when you run "sn.exe -d" allow it to remove the StrongName.


Here is an example sequence of commands:

C:\>sn -d someKey

Microsoft (R) .NET Framework Strong Name Utility Version 1.1.4322.573

Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Failed to delete container 'someKey' -- Unable to format error message

8013141C


The key container must still exist because I cannot create a new key

container, the error message is as follows:


C:\Projects\dload\Assembly>sn -i "C:\Keys.snk" someKey


Microsoft (R) .NET Framework Strong Name Utility Version 1.1.4322.573

Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.


Failed to install key pair -- Object already exists.



The hack to fix this is:



Browse to %SystemDrive%\Documents and Settings\AllUsers\ApplicationData\Microsoft\Crypto\RSA\MachineKeys

Grant rights to Adminstrators, or whatever group you belong to

Take Ownership of this folder (click Advanced under Security, and then click the Ownership tab at the top)

Apply the changes to the children ("Replicate permission...")

Then Try sn- d {KeyName}
Bingo ! and then re-install your assembly by signing it sn -i {KeyName}

No comments:

Post a Comment