背景: Google Developer Console でプロジェクトのサービス アカウントを設定し、サービス アカウントのメール、証明書、秘密のパスワードを使用して、GoogleAPisSample Plus.ServiceAccount で提供されている例に従っています。以下のスニペットは、私の Windows サービス アプリケーションの一部です。
var List<string> Scopes = new List<string> { "https://www.googleapis.com/auth/analytics.readonly" };
var credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(ServiceAccountEmail)
{
Scopes = Scopes
}.FromCertificate(certificate));
if(credential.RequestAccessTokenAsync(CancellationToken.None).Result)
{
AuthenticationKey = credential.Token.AccessToken;
}
このサービスをローカルの開発マシンにインストールして実行すると、credential.RequestAccessTokenAsync が正常に実行され、AccessToken が受信され、サービスが続行され、Analytics データの読み取りが正常に実行されます。
ただし、QA 環境 (Window Server 2008 R2 Standard) に展開して再度実行すると、credential.RequestAccessTokenAsync が呼び出されたときに次の例外がスローされます。
System.AggregateException: One or more errors occurred. ---> System.MissingMethodException: Method not found: 'System.Net.HttpStatusCode System.Net.Http.HttpResponseMessage.get_StatusCode()'.
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
at OurApplication.SchedulerService.GoogleAnalytics.OAuth2.ServiceAccountCredential.<RequestAccessTokenAsync>d__b.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.get_Result()
at OurApplication.SchedulerService.GoogleAnalytics.GADataFetcher.AuthenticateAndAuthorize()
at OurApplication.SchedulerService.GoogleAnalytics.GADataFetcher..ctor()
at OurApplication.SchedulerService.GoogleAnalytics.GoogleAnalyticsService.GoogleAnalyticsTopPerformances(Int32 sessID, String sessToken)
---> (Inner Exception #0) System.MissingMethodException: Method not found: 'System.Net.HttpStatusCode System.Net.Http.HttpResponseMessage.get_StatusCode()'.
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
at Seatwave.SchedulerService.GoogleAnalytics.OAuth2.ServiceAccountCredential.<RequestAccessTokenAsync>d__b.MoveNext()<---
packages.config に次の最新バージョンがあることを確認しました。
<package id="Microsoft.Bcl" version="1.1.6" targetFramework="net40" />
<package id="Microsoft.Bcl.Async" version="1.0.165" targetFramework="net40" />
<package id="Microsoft.Bcl.Build" version="1.0.13" targetFramework="net40" />
<package id="Microsoft.Net.Http" version="2.2.18" targetFramework="net40" />
app.config の次の内容:
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Threading.Tasks.Extensions.Desktop" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.165.0" newVersion="1.0.165.0" />
</dependentAssembly>
私の質問は、私の開発マシンで問題なく動作し、QA 環境 (Window Server 2008 R2 Standard) で上記の例外をスローするのはなぜですか?