title: Installing a certificate in a .MSI Custom Action doesn't work properly
body: <p>I'm trying to install a certificate in the Local Machine Store in a custom action.
  The certificate is installed, but when I use it to query AWS, I get this error:</p>
  
  <blockquote>
    <p>Object contains only the public half
    of a key pair. A private key must also
    be provided.</p>
  </blockquote>
  
  <p>The installer is running <em>elevated</em>, the target is Windows Vista.</p>
  
  <p>If I use a separate .exe to install the exact same certificate, using the exact same code, it works.
  So what is it that differs when installing a certificate using the Windows Installer?</p>
  
  <p>The code:</p>
  
  <pre><code>private void InstallCertificate(string certificatePath, string certificatePassword)
  {
    if (IsAdmin())
    {
      try
      {
        X509Certificate2 cert = new X509Certificate2(certificatePath, certificatePassword,
          X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);
  
        X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
        store.Open(OpenFlags.ReadWrite);
        store.Add(cert);
        store.Close();
      }
      catch (Exception ex)
      {
        throw new DataException("Certificate appeared to load successfully but also seems to be null.", ex);
      }
    }
    else
    {
      throw new Exception("Not enough priviliges to install certificate");
    }
  }
  </code></pre>