1509

Using GoogleApisClient ServiceAccountCredential calling RequestAccessTokenAsync throws Exception

Question:

Background: I have set up a Service Account for my project on Google Developer Console and using the Service Account Email, the Certificate and the secret password and following the example provide in the GoogleAPisSample Plus.ServiceAccount. The snippet below is part of my 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 I install and run this service on my local Development machine it does the credential.RequestAccessTokenAsync fine and receives the AccessToken and the service carries on and does the reading of the Analytics data fine.

However when it is deployed on our QA environment (Window Server 2008 R2 Standard) and run again, the following exception gets thrown when credential.RequestAccessTokenAsync is called:

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()<---

I have made sure I have the latest versions of the 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 the 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, My Question is why does it work fine on my Dev Machine and throws that Exception that I mentioned above on our QA Environment (Window Server 2008 R2 Standard)?

Answer1:

Found the solution! It was nothing to do with the Google Analytics API. It was a combination of the following two things:

<ol><li>Installing <a href="http://www.microsoft.com/en-gb/download/details.aspx?id=3556" rel="nofollow">KB2468871</a> .Net 4.0 Patch on our QA and Live Servers. </li> <li>

Updating to further newer versions of the 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>

</li> </ol>

Recommend

  • Combining expressions in R
  • Gradle java.util.logging.Logger output in unit tests
  • Powershell and Regex: How to replace a INI name,value pair inside a named section?
  • Record selectors in Haskell's Type Classes
  • Getting Http403 when saving files through django s3 middleware (but can save using boto in shell)
  • Finding distance of rectangle with known aspect ratio in OpenCV
  • Invoke method on generic type?
  • css hide “Choose File” button but display file after select
  • Ionic 3: The pipe '' could not be found [duplicate]
  • Bash: warning: command substitution: ignored null byte in input [closed]
  • Is it possible to take screenshot in unrooted android phone.? [duplicate]
  • Cosmos DB out of Memory exception while executing stored procedure
  • Ksql: Left Join Displays columns from stream but not tables
  • jquery animation delay when scrolled
  • Feature Extraction for MNIST Images Using PCA
  • format lookupset expression
  • Jmockit: Can't mock method toString of net.android.Uri class
  • Manipulating a group view in a ExpandableListView from the child view
  • How do I redirect an user back to the page they were trying to access once they log in? (Django)
  • Printing a flowdocument with dynamic data in WPF
  • ODBC connection to an .accdb file
  • Why dealing with Value is faster than with Reference for Struct?
  • JavaFX Embed Custom Font Not Working
  • Use 2D Text into 3D scenes in JavaFX results in blurry texts
  • No Gradle file syntax highlighting in Eclipse Mars.2
  • Corda: How to implement hierarchical relationships between state data persisted to H2
  • Can't hide status bar in AVPlayerViewController's portrait mode
  • cSPADE data mining in R using arulesSequences - Error while converting to “transactions” format
  • Haskell program that can handle any arbitrary deterministic finite automaton
  • openpyxl - adding new rows in excel file with merged cell existing
  • r - input value by user to dataframe via shiny
  • JavaScript Regex to Match Boundaries of Words with diacritics
  • Using redis as an LRU cache for postgres
  • Another “Cannot make static reference…” Question
  • `$http:badreq Bad Request Configuration` - from angular post method, what is wrong here?
  • How to handle div that is created dynamically in a table
  • php “page caching” solution suggestions for CMS Applications
  • Jersey serializes character value to ASCII equivalent numeric string
  • CAS 4 - Not able to retrieve the LDAP groups after successful authentication
  • What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?