title: Certificate is removed from the machine keyset when the application is closed
body: <p>I'm trying to deploy a certificate into a windows-my store in order to use it for SSL in IIS6.0.
  When the application is running I don't see any errors in SSLDiag output and everything works perfectly, but once I close the application SSLDiag shows an error:</p>
  
  <pre><code>#WARNING: You have a private key that corresponds to this certificate 
  but CryptAcquireCertificatePrivateKey failed
  </code></pre>
  
  <p>I checked the machine keyset and noticed that after I close my application it removes the file with a key which was created. Here is the location I checked:</p>
  
  <pre><code>C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys 
  </code></pre>
  
  <p>How can I preserve the create key file in a machine keyset?</p>
  
  <p>Here is the code I'm using:</p>
  
  <pre><code>        using(var openFileDialog = new OpenFileDialog())
          {
              if (openFileDialog.ShowDialog() == DialogResult.OK)
              {
                  var password = "password";
                  var certificate = new X509Certificate2(openFileDialog.FileName, password, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
                  var keystore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                  keystore.Open(OpenFlags.MaxAllowed);
                  keystore.Add(certificate);
                  keystore.Close();
              }
          }
  </code></pre>
  
  <p>I tried different variations of X509KeyStorageFlags, but the file is still removed from machine keyset once I close the app. Why the file is removed and how can I prevent it?</p>