Rakete1111 Rakete1111 - 6 months ago 90
C# Question

AggregateException when calling GetApplicationDefaultAsync()

I am trying to run the sample Vision API project. I basically copied and pasted the code

into my application and executed it.

This line (which is line #36-#37 in

GoogleCredential credential = GoogleCredential.GetApplicationDefaultAsync().Result;

throws a
Additional information: One or more errors occurred.

By examining
, I found out that the actual exception thrown is
Error deserializing JSON credential data.

Nonetheless, my cloud project is a basic project, with a Service Account, and Cloud Vision API enabled, nothing else. I checked that my environment variable was set to the JSON file by writing:


before the line above. The output of that (just before the crash) is (something like):


I checked the file, and it is the file that I got when I enabled my service account. Every property in it looks fine (i.e. project name is correct, path's correct, ...).

I installed the Google Cloud SDK and executed
gcloud beta auth application-default login
and authorized access to my cloud account.

Any ideas on what might be causing this?


By examining the detailed build log, I found out that the packages for the Google APIs had a dependency for Newtonsoft.Json version 9.0.1 (the latest at the time of this writing).

For whatever reason, the Google APIs packages have a dependency (which is installed along with them) on Newtonsoft.Json version 7.0.0.

The packages came with the wrong version!

Installing the latest version (9.0.1 in this case) fixes the issue.