title: remove private key from X509Certificate2
body: <p>I'm using the following method to export a certificate chain that contains two <code>X509Certificate2</code> objects: a certificate and the Certificate Authority that issued it:</p>
  
  <pre><code>public void ExportCertificateChain(X509Certificate2 cert, X509Certificate2 ca, string outPath, string password)
  {
      X509Certificate2Collection collection = new X509Certificate2Collection();
      collection.Add(cert); //certificate with private key
  
      //remove private key from CA, because don't want it to be usable for signing, we just want to install it to validate the first certificate
      ca.PrivateKey = null; //This throws an "Access Denied" exception!!!
      collection.Add(ca);
  
      var raw = collection.Export(X509ContentType.Pfx, password);
      File.WriteAllBytes(outPath, raw);                        
  }
  </code></pre>
  
  <p>the problem, as the comment in the code already tells, is that nulling the private key throws an exception that tells me "access denied"</p>
  
  <p>How do I properly remove the private key from a <code>X509Certificate2</code> object (or, alternatively, how do I get it from the store WITHOUT the private key in the first place?</p>