title: Invalid provider type specified when trying to access google analytics
body: <p>We keep getting the error below whenever we try to access the API to get current user numbers. I've tried a few things but cannot get to the bottom of this. Can anyone shed any light on whats wrong/missing? </p>
  
  <p>I should point out that thus runs perfectly fine on my local PC but is failing on the server.</p>
  
  <p>Here is the error:</p>
  
  <blockquote>
    <p>ConnectToAnalytics error:
    System.Security.Cryptography.CryptographicException: Invalid provider
    type specified. at
    System.Security.Cryptography.Utils.CreateProvHandle(CspParameters
    parameters, Boolean randomKeyContainer) at
    System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType
    keyType, CspParameters parameters, Boolean randomKeyContainer, Int32
    dwKeySize, SafeProvHandle&amp; safeProvHandle, SafeKeyHandle&amp;
    safeKeyHandle) at
    System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair() at
    System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32
    dwKeySize, CspParameters parameters, Boolean useDefaultKeySize) at
    System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()
    at
    Google.Apis.Auth.OAuth2.ServiceAccountCredential.Initializer.FromCertificate(X509Certificate2
    certificate) in
    C:\Users\mdril\Documents\GitHub\google-api-dotnet-client\Src\GoogleApis.Auth.DotNet4\OAuth2\ServiceAccountCredential.cs:line
    100 at Core.ConnectToAnalytics()</p>
  </blockquote>
  
  <p>This error is thrown when i run the code:</p>
  
  <pre><code>Public Shared Function GetRealtimeUsers() As String
      Try
          'realtime on site
          Dim gsService As AnalyticsService = Core.ConnectToAnalytics
          Dim RequestRealtime As DataResource.RealtimeResource.GetRequest = gsService.Data.Realtime.[Get]([String].Format("ga:{0}", "xxxxx"), "rt:activeUsers")
          Dim feed As RealtimeData = RequestRealtime.Execute()
  
          Return Int(feed.Rows(0)(0)).ToString()
      Catch ex As Exception
          Return "QUOTA USED"
      End Try
  </code></pre>
  
  <p>It error's here: RequestRealtime.Execute()</p>
  
  <p>For reference - here's the connect script:</p>
  
  <pre><code>Public Shared Function ConnectToAnalytics() As AnalyticsService
      Try
          Dim scopes As String() = New String() {AnalyticsService.Scope.Analytics, AnalyticsService.Scope.AnalyticsEdit, AnalyticsService.Scope.AnalyticsManageUsers, AnalyticsService.Scope.AnalyticsReadonly}
          Dim keyFilePath = HttpContext.Current.Server.MapPath("\xxx.p12")
          Dim serviceAccountEmail = "xxx"
          Dim certificate = New X509Certificate2(keyFilePath, "xxxx", X509KeyStorageFlags.Exportable)
          Dim credential = New ServiceAccountCredential(New ServiceAccountCredential.Initializer(serviceAccountEmail) With {.Scopes = scopes}.FromCertificate(certificate))
          Return New AnalyticsService(New BaseClientService.Initializer() With {.HttpClientInitializer = credential, .ApplicationName = "Client for xxx"})
      Catch ex As Exception
          Core.SendAdminStatusReport("ConnectToAnalytics error: " &amp; ex.ToString)
          Throw ex
      End Try
  End Function
  </code></pre>