title: X509 certificate not loading private key file on server
body: <p>I'm using the Google Analytics API and I followed this SO question to set up the OAuth: <a href="https://stackoverflow.com/a/13013265/1299363">https://stackoverflow.com/a/13013265/1299363</a></p>
  
  <p>Here is my OAuth code:</p>
  
  <pre><code>public void SetupOAuth ()
  {
      var Cert = new X509Certificate2(
          PrivateKeyPath, 
          "notasecret", 
          X509KeyStorageFlags.Exportable);
      var Provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, Cert)
      {
          ServiceAccountId = ServiceAccountUser,
          Scope = ApiUrl + "analytics.readonly"
      };
      var Auth = new OAuth2Authenticator&lt;AssertionFlowClient&gt;(Provider, AssertionFlowClient.GetState);
      Service = new AnalyticsService(Auth);
  }
  </code></pre>
  
  <p>PrivateKeyPath is the path of the private key file provided by Google API Console. This works perfectly on my local machine, but when I push it up to our test server I get</p>
  
  <pre><code>System.Security.Cryptography.CryptographicException: An internal error occurred.
  </code></pre>
  
  <p>with the following stack trace (irrelevant parts removed):</p>
  
  <pre><code>System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) +33
  System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromFile(String fileName, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle&amp; pCertCtx) +0
  System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags) +237
  System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags) +140
  Metrics.APIs.GoogleAnalytics.SetupOAuth() in &lt;removed&gt;\Metrics\APIs\GoogleAnalytics.cs:36
  Metrics.APIs.GoogleAnalytics..ctor(String PrivateKeyPath) in &lt;removed&gt;\Metrics\APIs\GoogleAnalytics.cs:31
  </code></pre>
  
  <p>So it appears as if it is having trouble loading the file.  I've checked the PrivateKeyPath that is passed in and it is pointing to the correct location.</p>
  
  <p>Any ideas? I don't know if this is an issue with the server, the file, the code or what.</p>