C# “C”;无效的providertype“;使用谷歌服务帐户

C# “C”;无效的providertype“;使用谷歌服务帐户,c#,google-api,google-analytics-api,google-api-dotnet-client,service-accounts,C#,Google Api,Google Analytics Api,Google Api Dotnet Client,Service Accounts,我不是c#方面的专家,这是我第一个使用google api和服务帐户的项目。我遇到了一个我不知道如何解决的问题。此代码在2台计算机上有效,但在第3台计算机上无效 第三台计算机在尝试运行时出现错误无效原型错误。 将代码检查为 有什么问题吗 使用代码: string[] scopes = new string[] { AnalyticsService.Scope.AnalyticsReadonly }; var keyFilePath = System.AppDomain.CurrentDomain

我不是c#方面的专家,这是我第一个使用google api和服务帐户的项目。我遇到了一个我不知道如何解决的问题。此代码在2台计算机上有效,但在第3台计算机上无效

第三台计算机在尝试运行时出现错误无效原型错误。
将代码检查为

有什么问题吗

使用代码:

string[] scopes = new string[] { AnalyticsService.Scope.AnalyticsReadonly };
var keyFilePath = System.AppDomain.CurrentDomain.BaseDirectory + "www.site.nl-012345678.p12";
string serviceAccountEmail = "name@api-project-000000000000.iam.gserviceaccount.com";
string applicationName = "www.applicationname.nl";
string password = "notasecret";

//loading the Key file<br>
var certificate = new X509Certificate2(keyFilePath, password, X509KeyStorageFlags.Exportable);
var credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
    Scopes = scopes
}.FromCertificate(certificate));

// setup the service
var service = new AnalyticsService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = applicationName
});
string[]scopes=新字符串[]{AnalyticsService.Scope.analyticsreadoly};
var keyFilePath=System.AppDomain.CurrentDomain.BaseDirectory+“www.site.nl-012345678.p12”;
字符串serviceAccountEmail=”name@api-项目-000000000000.iam.gserviceaccount.com”;
字符串applicationName=“www.applicationName.nl”;
字符串password=“notasecret”;
//正在加载密钥文件
var certificate=new X509Certificate2(keyFilePath,密码,x509keystrageflags.Exportable); var-credential=新的ServiceAccountCredential( 新ServiceAccountCredential.初始值设定项(serviceAccountEmail) { 范围=范围 }.FromCertificate(证书)); //设置服务 var服务=新的AnalyticsService(新的BaseClientService.Initializer() { HttpClientInitializer=凭证, ApplicationName=ApplicationName });
编辑(添加stacktrace):

Serverfout-in-toepass/。
Ongeldig providertype opgegeven。
Beschrijving:Er是一个非常好的选择,它是一个非常好的选择。Raadpleeg de Stacktracing voor meer informatie over deze fout en de oorsprong ervan in de code。
详细信息:System.Security.Cryptography.Cryptography异常:Ongeldig providertype opgegeven。
布朗福特:
Regel 37:var certificate=new X509Certificate2(keyFilePath,密码,x509keystrageflags.Exportable);
Regel 38:var credential=新ServiceAccountCredential(新ServiceAccountCredential.Initializer(serviceAccountEmail)
第39条:{
Regel 40:范围=范围
Regel 41:}.FromCertificate(certificate));
Bronbestand:C:\inetpub\wwwroot\git\ttldashboard\ttldashboard\Helpers\GoogleAnalytics.cs Regel:39
堆栈跟踪:
[加密例外:Ongeldig providertype Opgeven。
]
System.Security.Cryptography.Utils.CreateProvHandle(CspParameters,Boolean randomKeyContainer)+5265821
System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType、CspParameters parameters、Boolean randomKeyContainer、Int32 dwKeySize、SafeProvHandle和SafeProvHandle、SafeKeyHandle和SafeKeyHandle)+94
System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()+136
System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize,CspParameters,Boolean useDefaultKeySize)+203
System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()+240
C:\Users\cloudsharp\Documents\GitHub\Google api dotnet client\Src\Support\GoogleApis.Auth.PlatformServices\u Shared\OAuth2\ServiceAccountCredential.cs:115中的Google.api.Auth.OAuth2.Initializer.FromCertificate(X509Certificate2证书)
C:\inetpub\wwwroot\git\ttldashboard\ttldashboard\Helpers\GoogleAnalytics.cs中的ttldashboard.Helpers.GoogleAnalytics.getAnalytics()文件:39
ttldashboard.Helpers.GoogleAnalytics.GetGoogleExitClicks(Int32 locatieId,字符串startDate,字符串stopDate)位于C:\inetpub\wwwroot\git\ttldashboard\ttldashboard\Helpers\GoogleAnalytics.cs:146
C:\inetpub\wwwroot\git\ttldashboard\ttldashboard\Controllers\DashboardController.Index()中的ttldashboard.Controllers.DashboardController.Index():67
lambda_方法(闭包、控制器基、对象[])+87
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext ControllerContext,IDictionary`2参数)+229
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext ControllerContext,ActionDescriptor ActionDescriptor,IDictionary`2参数)+35
System.Web.Mvc.Async.AsyncControllerActionInvoker.b_u39(IAsyncResult asyncResult,ActionInvoking innerInvokeState)+39
System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)+67
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)+42
System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d()+72
System.Web.Mvc.Async.c__显示类46.b_3f()+386
System.Web.Mvc.Async.c__显示类46.b_3f()+386
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)+42
System.Web.Mvc.Async.c__显示类2b.b__1c()+38
System.Web.Mvc.Async.c__显示类21.b__1e(IAsyncResult asyncResult)+186
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+38
System.Web.Mvc.Controller.b_u1d(IAsyncResult asyncResult,ExecuteCorerate innerState)+29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+65
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+53
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+36
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)+38
System.Web.Mvc.MvcHandler.b_uu5(IAsyncResult asyncResult,ProcessRequestState innerState)+44
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+65
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+399
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+137
版本:微软.NET框架版本:4.0.30319;ASP.NET版本:4.6.1038.0

这可能是该计算机上证书的加密问题。如果我可以重新创建它,我可能会玩它,只是为了看看是什么导致它,但因为我不能在这里是一个“可能”的方式围绕它

转到谷歌开发者控制台。D
Serverfout in toepassing /.  
Ongeldig providertype opgegeven.
Beschrijving: Er is een onverwerkte uitzondering opgetreden tijdens het uitvoeren van de huidige webaanvraag. Raadpleeg de stacktracering voor meer informatie over deze fout en de oorsprong ervan in de code.

Details van uitzondering: System.Security.Cryptography.CryptographicException: Ongeldig providertype opgegeven.


Fout in bron:


Regel 37:             var certificate = new X509Certificate2(keyFilePath, password, X509KeyStorageFlags.Exportable);
Regel 38:             var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail)
Regel 39:             {
Regel 40:                 Scopes = scopes
Regel 41:             }.FromCertificate(certificate));


Bronbestand: C:\inetpub\wwwroot\git\ttldashboard\ttldashboard\Helpers\GoogleAnalytics.cs    Regel: 39

Stacktracering:


[CryptographicException: Ongeldig providertype opgegeven.
]
   System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer) +5265821
   System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle) +94
   System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair() +136
   System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize) +203
   System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey() +240
   Google.Apis.Auth.OAuth2.Initializer.FromCertificate(X509Certificate2 certificate) in C:\Users\cloudsharp\Documents\GitHub\google-api-dotnet-client\Src\Support\GoogleApis.Auth.PlatformServices_Shared\OAuth2\ServiceAccountCredential.cs:115
   ttldashboard.Helpers.GoogleAnalytics.GetAnalyticsService() in C:\inetpub\wwwroot\git\ttldashboard\ttldashboard\Helpers\GoogleAnalytics.cs:39
   ttldashboard.Helpers.GoogleAnalytics.GetGoogleExitClicks(Int32 locatieId, String startDate, String stopDate) in C:\inetpub\wwwroot\git\ttldashboard\ttldashboard\Helpers\GoogleAnalytics.cs:146
   ttldashboard.Controllers.DashboardController.Index() in C:\inetpub\wwwroot\git\ttldashboard\ttldashboard\Controllers\DashboardController.cs:67
   lambda_method(Closure , ControllerBase , Object[] ) +87
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +229
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
   System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +67
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +72
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +386
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +386
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +38
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +186
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +44
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +399
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +137


Versiegegevens: Microsoft .NET Framework Versie:4.0.30319; ASP.NET Versie:4.6.1038.0
 GoogleCredential credential;
 using (var stream = new FileStream(serviceAccountCredentialFilePath, FileMode.Open, FileAccess.Read))
       {
       credential = GoogleCredential.FromStream(stream)
                    .CreateScoped(scopes);
       }

 // Create the service.
 var service = new AnalyticsService(new BaseClientService.Initializer()
    {
    HttpClientInitializer = credential,
    ApplicationName = "Google Authentication Sample",
    });
string sKeyFile = System.Web.Hosting.HostingEnvironment.MapPath("/Keys/" + ServiceAccountKey);
if (!System.IO.File.Exists(sKeyFile))
{
    throw new Exception("Key file can't be found! " + sKeyFile);
}

var certificate = new X509Certificate2(sKeyFile, "notasecret", 
                   X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet);