Visual Studio 2010 “Cannot import the following key file” error

Yesterday I was trying to open an old project I haven’t opened yet on my new computer. I got a lot of errors, one of which was:

Cannot import the following key file: <certname>.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name:  <VS_KEY>

This error occurred because the project assemblies were strong signed with a certificate and the certificate was password protected.

First I tried to enter the password through Visual Studio, but that didn’t work at all.

Then I removed the pfx cert from the project and added it back with the same password. This worked on my computer, but when I checked in the changes the same error occurred on build servers.

Then I came across this solution:

  • Open Visual Studio Command Prompt(2010): Start->Microsoft Visual Studio 2010->Visual Studio Tools->Visual Studio Command Prompt(2010)
  • Navigate to <CertName>.pfx
  • Enter the following command: sn -i [CertName].pfx [VS_KEY]
  • Then enter the password for the certificate and you’re done

Leave a Reply