Microsoft CSP and Keys with Multiple Users
We use the AssemlyKeyNameAttribute attribute in our AssemblyInfo files to set our private key. It looks like this:
[assembly: AssemblyKeyNameAttribute("MyKey")]
To use it, you store the key (in this case "MyKey") in the CSP on your machine. When your assembly gets built, it uses the key from the CSP.
We have automated builds (using Visual Build Professional from
Kinook -- awesome tool!!!). As part of the process, it installs the key into the CSP. So, if you've ever done a "sn -i" operation and seen a message like this, keep reading:
Failed to install key pair -- Object already exists.
This message was very puzzling for a while. We knew the key didn't exist, but we were receiving this message. So, we tried deleting the key with "sn -d".
You get the following:
Failed to delete container 'MyKey' -- Unable to format error message 8013141C
How's that for a vague message?
So we know it failed. Finally, we figured out that the key did exist on the machine, but it was put into the CSP by a different user. We had to log on as that user and delete the key. and then we could add it under a different user.
Incidentally, you get the same message if you try to delete a key that doesn't exist:
Failed to delete container 'MyKey' -- Unable to format error message 8013141C
So that's not necessarily a clue that the key exists under a different user. It just tells you something went wrong and not why.
Microsoft really needs to iron this out. Ideally, each user on a machine should be able to save the same key name to the CSP separate from any other user and it shouldn't conflict. If that's not the case, then they CSP should be for the machine, not each user. What we have is a really strange hybrid that can cause headaches.