1

인 C# "invalid providertype"C# 전문가가 아니며 google api 및 서비스 계정이있는 첫 번째 프로젝트입니다. 내가 해결 방법을 모르는 문제가 생겼다. 이 코드는 2 대의 컴퓨터에서 작동하지만 3 번에는 작동하지 않습니다.Google 서비스 계정이

세 번째 컴퓨터가 실행하려고하면 잘못된 프로토 타입 오류가 발생합니다.
Documentation Google API - Service account

어떤 코드가 문제입니까?

사용 된 코드 :

string[] scopes = new string[] { AnalyticsService.Scope.AnalyticsReadonly }; 
var keyFilePath = System.AppDomain.CurrentDomain.BaseDirectory + "www.site.nl-.p12"; 
string serviceAccountEmail = "[email protected]"; 
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 
}); 

편집 (추가 스택 트레이스) :

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 
+0

예외 (innerexception (s), stacktrace (s) 등)에 대한 자세한 내용을 게시 할 수 있습니까? –

+1

작동하지 않는 컴퓨터에서 약간의 정보를 사용할 수 있습니다. @ JevgeniGeurtsen 우리는 던지는 예외를 모두 볼 필요가있다. – DaImTo

+0

전체 스택 추적을 추가했습니다. 이것이 충분합니까? – xAndyx

답변

1

이것은 아마 컴퓨터에 인증서와 암호화 문제입니다. 내가 그것을 재창조 할 수 있다면 아마도 그걸 가지고 무엇이 원인인지 알 수있을 것입니다. 그러나 여기서 그럴 수 없기 때문에 그 주위에 "가능한"방법이 있습니다.

google 개발자 콘솔로 이동하십시오. 서비스 계정 .p12 파일 대신 서비스 계정 .Json 파일을 다운로드하십시오. 그런 다음이 코드를 대신 사용하십시오.

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", 
    }); 

실제로 무엇이 문제의 원인인지 알고 싶다면 누군가를 찾을 수 있는지 확인하십시오.

+0

json 파일로 전환 해 주셔서 문제가 해결되었습니다! AnalyticsReportingService() btw를 사용할 수 없어 AnalyticsService()를 대신 사용해야했습니다. – xAndyx

+0

AnalyticsReportingService는 Google 웹 로그 분석 v4는 AnalyticsService v3입니다. 죄송합니다. 내 코드를 복사하는 대신 코드를 살펴 보았습니다. 올바른 서비스로 답변을 업데이트했습니다. – DaImTo

관련 문제