“Object Already Exists” error when generating a strong name key in Visual Studio

For about a day now I have been receiving an error message whenever I try and generate a strong-name key for an assembly using the Signing tab of the project properties window in Visual Studio.

Goggling the error message reveals that in almost all cases this error message is displayed as a result of sn.exe failing for various reasons. Visual Studio’s error message is unhelpful with respect to solving the problem because it masks the reason for the failure

Running sn from a command prompt yields a much more helpful message:

sn –k key.snk

Failed to generate a strong name key pair — Access is denied.

The message is still a little ambiguous because it doesn’t specify what it is that the system is denying access to, however a little investigation with the excellent Process Monitor tool from SysInternals (now Microsoft) will reveal this information.

In my case  the error occurred because I did not have correct permissions (read: none at all) to access "C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys". After granting myself read and write permissions to this folder key generation worked once more.

As stated above, there are lots of reasons for this error message, and it’s best to get the error directly from sn.exe to get a better idea of what’s going on before modifying your system

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s