.net - Using GoogleApisClient ServiceAccountCredential calling RequestAccessTokenAsync throws Exception -


background: have set service account project on google developer console , using service account email, certificate , secret password , following example provide in googleapissample plus.serviceaccount. snippet below part of windows service application:

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;                 } 

when install , run service on local development machine credential.requestaccesstokenasync fine , receives accesstoken , service carries on , reading of analytics data fine.

however when deployed on our qa environment (window server 2008 r2 standard) , run again, following exception gets thrown when credential.requestaccesstokenasync called:

system.aggregateexception: 1 or more errors occurred. ---> system.missingmethodexception: method not found: 'system.net.httpstatuscode system.net.http.httpresponsemessage.get_statuscode()'.    @ microsoft.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task)    @ microsoft.runtime.compilerservices.taskawaiter.handlenonsuccess(task task)    @ ourapplication.schedulerservice.googleanalytics.oauth2.serviceaccountcredential.<requestaccesstokenasync>d__b.movenext()    --- end of inner exception stack trace ---    @ system.threading.tasks.task`1.get_result()    @ ourapplication.schedulerservice.googleanalytics.gadatafetcher.authenticateandauthorize()    @ ourapplication.schedulerservice.googleanalytics.gadatafetcher..ctor()    @ 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()'.    @ microsoft.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task)    @ microsoft.runtime.compilerservices.taskawaiter.handlenonsuccess(task task)    @ seatwave.schedulerservice.googleanalytics.oauth2.serviceaccountcredential.<requestaccesstokenasync>d__b.movenext()<--- 

i have made sure have latest versions of following in 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" /> 

and following in 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> 

so, question why work fine on dev machine , throws exception mentioned above on our qa environment (window server 2008 r2 standard)?

found solution! nothing google analytics api. combination of following 2 things:

  1. installing kb2468871 .net 4.0 patch on our qa , live servers.
  2. updating further newer versions of following dlls in app.config:

    <dependentassembly> <assemblyidentity name="system.runtime" publickeytoken="b03f5f7f11d50a3a" culture="neutral" /> <bindingredirect oldversion="0.0.0.0-2.6.6.0" newversion="2.6.6.0" /> </dependentassembly> <dependentassembly> <assemblyidentity name="system.threading.tasks" publickeytoken="b03f5f7f11d50a3a" culture="neutral" /> <bindingredirect oldversion="0.0.0.0-2.6.6.0" newversion="2.6.6.0" /> </dependentassembly> <dependentassembly> <assemblyidentity name="system.net.http" publickeytoken="b03f5f7f11d50a3a" culture="neutral" /> <bindingredirect oldversion="0.0.0.0-2.2.18.0" newversion="2.2.18.0" /> </dependentassembly> <dependentassembly> <assemblyidentity name="system.net.http.primitives" publickeytoken="b03f5f7f11d50a3a" culture="neutral" /> <bindingredirect oldversion="0.0.0.0-2.2.18.0" newversion="2.2.18.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> </assemblybinding>


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -