title: C# WCF client error "The private key is not present in the X.509 certificate"
body: <p>I'm am trying to create a very simple WCF client application which will send SOAP messages to a 3rd party service. All the messages must be digitally signed. It's really a proof of concept before I add the code to a larger application.</p>
  
  <p>I have a .cer file containing the certificate and a .pem file containing the private key. What I have been trying to do is load the certificate using the .cer file then fire off a message. But I get the following error "The private key is not present in the X.509 certificate".</p>
  
  <p>The problem, well one of the problems, is that I really know almost nothing about WCF, digital certificates, private keys and all that guff. I've done some reading, I've Googled till I'm blue in the face and I've not got anywhere. </p>
  
  <p>If I open the .cert file there is a section labelled "BEGIN ENCRYPTED PRIVATE KEY" which suggests that the private key is included in the certificate. So, why am I getting a message saying that it is not present? Also, if the private key does need to be added to the certificate how do I do it?</p>
  
  <p>Here basically what I'm doing. It's not my actual code, but it includes all the relevant stuff:</p>
  
  <pre><code>MyWSClient c = new MyWSClient();
  c.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(@"pathToFile.cer");
  c.SomeValidCall();
  </code></pre>