Partager via


An error occurred while signing: Key not valid for use in specified state

When a user tries to publish a ClickOnce application after changing the user account password, it would fail with one of below error messages:

“Cannot publish because a project failed to build.”
“An error occurred while signing: Key not valid for use in specified state.”
“Error msb3482 an error occurred while signing key not valid for use in specified state” Ex. https://msdn.microsoft.com/en-us/library/ms228227(v=vs.90).aspx

Please find the below steps to reproduce the issue:

1. Create a simple Windows Form application in Visual Studio.
2. Without changing any properties of the application, right click the project file and “publish” the application.
(A test certificate is automatically created by Visual Studio and stored under the project folder. )
3. Change the password of the local user account.
4. Logoff from the computer and login back to the computer using the same user account.
5. Open the same project that was created in step1, and without changing any properties of the application, right click the project file and “publish” the application.
6. The above error would occur.

 Resolution:

The above issue occurs due to ClickOnce application was not signed with the certificate after re-logging to the system using new user account password. In order to resolve the issue just re-sign the application after re-logging. For example, first time you sign the app using this certificate and publish it. Then change the password for the current user and log off/re-login to the system. Now sign the app again with the same certificate and publish the application. You should be able to publish the application successfully.